Need help multiplying matrices of different sizes

3 views (last 30 days)
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 Comments
Sofija Radulovic
Sofija Radulovic on 14 Jun 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 on 14 Jun 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.

Sign in to comment.

Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!