Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2

1 Ansicht (letzte 30 Tage)
Xindex = zeros(217,2);
Xval = zeros(201,1,217);
for index = 1:217
Xval(:,1,index) = A(:,3,index);
for rowidx = 1:201
if(Xval(rowidx,1,index)>7.227 && Xval(rowidx,1,index)<7.2510)
r = 1;
c = 1;
Xindex(r, c) = [index rowidx];
r = r + 1;
c = c + 1;
end
end
end
The underlined code is causing the error. I am not sure what is wrong as Xindex has 217 rows and 2 columns, I am trying to fit two values alongside each other in the same row. Why is a size mismatch occuring?
Please help, thanks in advance!

Akzeptierte Antwort

James Tursa
James Tursa am 3 Nov. 2021
Bearbeitet: James Tursa am 3 Nov. 2021
Does this do what you want:
Xindex(r, :) = [index rowidx];
You can get rid of c altogether since it isn't needed. And you need to move the r = 1 line to up above the start of the for loops.

Weitere Antworten (0)

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!

Translated by