Unable to perform assignment because the size of the left side is 2032-by-1 and the size of the right side is 1-by-2243277.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Miguel Albuquerque
el 12 de Jun. de 2022
Comentada: Miguel Albuquerque
el 13 de Jun. de 2022
Hey guys, thanks in advance
I have a matrix range_compression(2032x400). Each row corresponds to a position of a radar and columns correspond to signals in frequency domain.
For each column I apply a function that transforms that signal to time domain. However the code I have is getting this error
Unable to perform assignment because the size of the left side is 2032-by-1 and the size of the right side is 1-by-2243277.
I would like to save the outputs of the function in a matrix 2243277x400(columns of range_compression). How can I solve this error?
Thanks a lot
[rows,columns]=size(Range_compression);
output = zeros(rows, columns);
for col = 190 : 300
% Get a column
thisColumn = Range_compression(:, col);
% Convert it to time domain.
[time_compression,range_compressed]=freq2time(thisColumn, doppler_freqSurv);
% Save the output
time_compression=time_compression*c;
output(:, col)= time_compression;
output2(:, col)= range_compressed;
end
Respuesta aceptada
Walter Roberson
el 12 de Jun. de 2022
f=linspace(-max_f,max_f,2*max_f*(length(Fsig)-1)/(max(Fsig)-min(Fsig))+1);
linspace with two parameters always generates 100 points
t=linspace(-0.5/(f(2)-f(1)),0.5/(f(2)-f(1)),length(f)+1);
t=t(1:end-1);
One longer than f but throw away one, so t is the same length as f which is 100. t is the first output of freq2time so the first output will be 1 x 100.
[time_compression,range_compressed]=freq2time(thisColumn, doppler_freqSurv);
% Save the output
time_compression=time_compression*c;
output(:, col)= time_compression;
With time_compression being that vector length 100, then the assignment into output can only work if output has 100 rows.
[rows,columns]=size(Range_compression);
output = zeros(rows, columns);
not impossible but seems unlikely.
3 comentarios
Walter Roberson
el 13 de Jun. de 2022
No, I do not think there is a way you can solve that problem.
I think you need to redesign your code.
You need to create a "contract" for each function: for each function, given the size of the input variables, each function must guarantee that it returns a particular size of output based upon the input variables.
And then you need to write your other code in terms of those "contracts".
For example if you write a function that is guaranteed to return a row vector with number of elements equal to the number of columns in the input variable, then do not try to store the results into an array in a slot that is sized according to the number of rows in the input variable.
Track your sizes. And during development, you can put in assert() or similar statements to trigger an error if the function is not returning back the size you expect; you would use that information to trace back to figure out why you are getting the wrong size.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!