help me to solve this

I array={2,5,7,12} ; D is an Image attached
H=[];
for i=1:4
for j=1:10
if(D(I(i),j)<=10)
H=[H,j]; %H is an array.
end
end
I am getting results like 2 12 5 7 5 6 7 2 12
I want something like this. I don't know to store it.
H(1):2 12
H(2):5 7
H(3):5 6 7
H(4):2 12

Réponses (1)

Walter Roberson
Walter Roberson le 6 Mai 2017

0 votes

Replace
H=[H,j]; %H is an array.
with
H{i}(end+1) = j;

5 commentaires

Ad
Ad le 7 Mai 2017
Thank you so much for your response.
I am getting this error
"Cell contents reference from a non-cell array object."
Change the
H=[];
to
H = {};
Ad
Ad le 7 Mai 2017
Now it is saying
"Index exceeds matrix dimensions."
When it stops due to the error, please show
max(I)
class(I)
size(D)
size(H)
i
j
Question: why is it that your code
if(D(I(i))<=10)
does not depend upon j?
Ad
Ad le 7 Mai 2017
Sorry.
if(D(I(i),j)<=10)
Size of D 12*12

Connectez-vous pour commenter.

Question posée :

Ad
le 6 Mai 2017

Modifié(e) :

Ad
le 7 Mai 2017

Community Treasure Hunt

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

Start Hunting!

Translated by