Need help multiplying matrices of different sizes

2 vues (au cours des 30 derniers jours)
Sofija Radulovic
Sofija Radulovic le 10 Juin 2020
Commenté : Walter Roberson le 14 Juin 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 commentaires
Sofija Radulovic
Sofija Radulovic le 14 Juin 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 le 14 Juin 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by