Problems with different length vectors introduction into an array

1 回表示 (過去 30 日間)
Gonzalo Molina
Gonzalo Molina 2020 年 6 月 5 日
コメント済み: Ameer Hamza 2020 年 6 月 5 日
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 件のコメント
Gonzalo Molina
Gonzalo Molina 2020 年 6 月 5 日
Perfect, thank you very much.
Have a nice day.
Ameer Hamza
Ameer Hamza 2020 年 6 月 5 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by