Problems with different length vectors introduction into an array

1 次查看(过去 30 天)
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.

采纳的回答

Ameer Hamza
Ameer Hamza 2020-6-5
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by