Output matrix dimension mismatch in for loop
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Catherine
am 27 Feb. 2017
Kommentiert: Catherine
am 27 Feb. 2017
Hi guys, I am having problem with storing the peaks of my data in a for loop. It said subscripted assignment dimension mismatch. I am guessing may be the number of peaks is not the same for all the values in the loop. Here is a simplified version of my codes:
q = 0;
g= 0;
for A = 0:pi/2:4*pi;
for B = 1:1:10;
y(q+1) = sin(A*B);
H(q+1) = B;
q = q+1;
end
q = 0;
C(g+1,:) = y;
[pks,locs] = findpeaks(C(g+1,:));
D(g+1,:) = pks;
E(g+1,:) = B(locs);
g = g+1;
end
plot(H,y)
g = 0;
How can I store my peaks and the corresponding x values?
Thanks guys!
0 Kommentare
Akzeptierte Antwort
Jan
am 27 Feb. 2017
Bearbeitet: Jan
am 27 Feb. 2017
Please post the complete error message, such that we do not have to guess the line, which causes the problem. I guess boldly:
C(g+1,:) = y;
Here y is a [1, q+1] row vector. Assigning it to a row of C requires, the C has the same number of columns. But this cannot be true over multiple iterations.
You did not include comments in the code. Without a description of what you want to achieve, suggestion a solution is an educated guess only.
[EDITED] The number of peaks differ between the iterations (I guess), then store them in a cell array:
Av = 0:pi/2:4*pi;
D = cell(1, numel(Av));
for A = Av
...
[pks,locs] = findpeaks(C(g+1,:));
D{g+1} = pks;
...
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!