Need help multiplying matrices of different sizes

3 ビュー (過去 30 日間)
Sofija Radulovic
Sofija Radulovic 2020 年 6 月 10 日
コメント済み: Walter Roberson 2020 年 6 月 14 日
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 件のコメント
Sofija Radulovic
Sofija Radulovic 2020 年 6 月 14 日
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 2020 年 6 月 14 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by