Problems with different length vectors introduction into an array

1 vue (au cours des 30 derniers jours)
Gonzalo Molina
Gonzalo Molina le 5 Juin 2020
Commenté : Ameer Hamza le 5 Juin 2020
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.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 5 Juin 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 commentaires
Gonzalo Molina
Gonzalo Molina le 5 Juin 2020
Perfect, thank you very much.
Have a nice day.
Ameer Hamza
Ameer Hamza le 5 Juin 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by