Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 22 de Nov. de 2019
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.
Respuestas (1)
Walter Roberson
el 22 de Nov. de 2019
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 comentarios
Walter Roberson
el 22 de Nov. de 2019
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.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!