Need help multiplying matrices of different sizes

2 visualizaciones (últimos 30 días)
Sofija Radulovic
Sofija Radulovic el 10 de Jun. de 2020
Comentada: Walter Roberson el 14 de Jun. de 2020
I am having trouble multuplying the dtnewnew matrix by the acceleration matrix. Both of them should be vectors but they are vectors of different length. How do I make it so that they are the same length? Please note that the length of the acceleration vector will change since I am picking 50 random files out of 7092 files
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate
the appropriate size for that dimension.
Error in newearthquakes (line 19)
dtnewnewnew=reshape(dtnewnew,size([]));
HERE IS MY CODE:
%IMPORT THE ACCELERATION FILE AND GETTING 50 ACCELERATION FILES
%making loop so it does this 50 times
%picking 50 random numbers
for i=1:1:50
a=randi([1,7092]);
name=['R',num2str(a),'.txt'];
data=importdata(name);
acceleration=data(:);
newacceleration = acceleration(1:3516,:)
%trouble matching the end of the acceleration array to the 3516 of the
%excel file
%IMPORT THE dt FILE from excel
excelfile = xlsread('Final_NGA_Flatfile.xlsx');
%TO GET THE X VALUES, MULTUPLY DT BY ACCELERATION VALUES
dt=['D',num2str(a-1)];
dtnewnew=dt(:);
dtnewnewnew=reshape(dtnewnew,size([]));
xvalues(:,i)=bsxfun(@times,dtnewnew,newacceleration);
%PLOT/LABEL
plot=scatter(xvalues,newacceleration,'.');
xlabel('time');
ylabel('acceleration');
title('Earthquake Data (acceleration vs. time)');
end
  3 comentarios
Sofija Radulovic
Sofija Radulovic el 14 de Jun. de 2020
the acceleration matrix is changing because it is randomized, i cannot upload the data files because there are 7000 of them, and the dtnewnew matrix is 7094 x 1
Walter Roberson
Walter Roberson el 14 de Jun. de 2020
size([]) is [0 0], and reshaping dtnewnew to 0 by 0 will fail unless dtnewnew is already empty.
If dtnewnewnew is intended to be a row vector, then just take dtnewnew.' since dtnewnew is certain to be a column vector.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by