フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Unable to perform assignment because the size of the left side is 1-by-10000 and the size of the right side is 1-by-20000. how to solve ??

1 回表示 (過去 30 日間)
pavan kumar
pavan kumar 2019 年 11 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
clearvars;close all;clc;
count=0;
k=10e3:10e3:100e3;
for i=1:1:10
p(count+1,:)=rand(1,k(i));
count=count+1;
end
  2 件のコメント
Stephen23
Stephen23 2019 年 11 月 22 日
MATLAB arrays must be rectangular (i.e. cannot be "ragged"), so this allocation will not work because the number of elements changes on each iteration:
p(count+1,:)=rand(1,k(i));
You might be able to use a cell array.
pavan kumar
pavan kumar 2019 年 11 月 22 日
thank u sir..
please suggest me how to use a cell array ??

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 11 月 22 日
You are increasing the number of values generated for each element of the loop. How do you expect to store that continually increasing number of values as rows of a matrix? A matrix cannot have a different number of columns for each row.
  2 件のコメント
pavan kumar
pavan kumar 2019 年 11 月 22 日
thank u sir.
sir, how can i store differernt coloumns in a same matrix ??
Walter Roberson
Walter Roberson 2019 年 11 月 22 日
k = 10e3:10e3:100e3;
p = [];
for i = 1:1:10
if size(p,1) < k(i)
p(end:k(i),1:i) = nan; %expands rows and columns
end
p(1:k(i), i) = rand(k(i), 1);
p(k(i):end, i) = nan;
end
This is not as efficient as it could be. More efficient would be to figure out the largest size ahead of time:
k = 10e3:10e3:100e3;
maxk = max(k);
N = 10;
p = nan(maxk, N);
for i = 1:1:N
p(1:k(i), i) = rand(k(i), 1);
end
Both of these pad the short columns with NaN to signal missing data.
Both versions are coded to account for the possibility that you might have shorter columns after longer columns but must still pad with nan properly.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by