fixing an error for calling a variable in an array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
sampath kumar punna
am 25 Okt. 2019
Bearbeitet: Stephen23
am 25 Okt. 2019
Y = [1 7
3 9
11 12
15 18
22 12
12 23
15 19
10 22
17 28
111 123]
z= [ 9 12 18 12 23 19 22 28 123]
for i= 1: length(z)
out(i) = Y(find(Y(:,2) == z(:,i)))
end
this code shows an error while executing (Unable to perform assignment because the left and right sides have a different number of
elements.)
can anyone please fix this error
thanks
0 Kommentare
Akzeptierte Antwort
Stephen23
am 25 Okt. 2019
Bearbeitet: Stephen23
am 25 Okt. 2019
I suspect that you want something like this:
>> Y = [1,7;3,9;11,12;15,18;22,12;12,23;15,19;10,22;17,28;111,123]
Y =
1 7
3 9
11 12
15 18
22 12
12 23
15 19
10 22
17 28
111 123
>> z = [9,12,18,12,23,19,22,28,123]
z =
9 12 18 12 23 19 22 28 123
>> [~,idx] = ismember(z,Y(:,2));
>> out = Y(idx,:)
out =
3 9
22 12
15 18
22 12
12 23
15 19
10 22
17 28
111 123
Using a loop is unlikely to be a neat or efficient solution.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!