Problems with different length vectors introduction into an array
1 view (last 30 days)
Show older comments
Good morning, I have dimensioning problems with the following loop:
for i = 1:rows
for j = 1:columns
if vimage(i,j) ~=1
for z = 1:(colors-1)
if vimage(i,j) >= content_coords(z,3) && vimage(i,j) < content_coords((z+1),3)
real_content(i,j,:) = content_coords(z,4):0.1:content_coords(z,5);
elseif vimage(i,j) >= content_coords(colors,3)
real_content(i,j,:) = content_coords(colors,4):0.1:content_coords(colors,5);
end
end
else
real_content(i,j,:) = NaN; %or do nothing
end
end
end
vimage corresponds to a 300*300 array with different values
The third column (3) of content_coords contains the values to be compared with those in vimage, then the fourth (4) and the fifth column (5) contain a minimum and a maximum value respectively.
Even tho all the maximums and minimums are 0.1 multiples, the length of content_coords(z,4):0.1:content_coords(z,5) is different depending on the case.
The problem comes when using (i, j, :) which leads to the following error: "Unable to perform assignment because the size of the left side is 1-by-1-by-5 and the size of the right side is 1-by-5."
I've tried to create real_content array with Nan prior to the execution with the maximum dimensions but still not working.
Thank you in advance for your help and time.
Gonzalo.
0 Comments
Accepted Answer
Ameer Hamza
on 5 Jun 2020
In MATLAB, you cannot save data of varying dimensions in a simple array. You need to use cell array if the dimension of data is changing.
real_content = cell(rows, columns); % initialize
%% code of for-loops
real_content{i,j} = content_coords(z,4):0.1:content_coords(z,5);
4 Comments
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!