Need help multiplying matrices of different sizes
조회 수: 3 (최근 30일)
이전 댓글 표시
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
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 Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!