Output matrix dimension mismatch in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Jan
2017 年 2 月 27 日
編集済み: Jan
2017 年 2 月 27 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!