필터 지우기
필터 지우기

Error using .* matrix dimensions must agree

조회 수: 1 (최근 30일)
Jenny
Jenny 2016년 1월 5일
댓글: Jenny 2016년 1월 5일
I am plotting polar plots of my data. The first polar plot plots fine. The second plot plots fine if I run it on its own but if I run it after the first plot then I receive the error: Error using .*
I can see that the index (ind) that is being used changed from 48 to 26 but I do not understand why.
I would appreciate help in getting my matrix dimensions to agree.
%%Import data from spreadsheet
[filename,pathname]=uigetfile('*.xlsx','Select the file');
data = xlsread(filename);
% Allocate imported array to column variable names
Dir = data(:,1);
Max = data(:,2);
Mean = data(:,3);
Count = data(:,4);
TotFlow = data(:,5);
% Clear temporary variables
clearvars data raw;
%%Max
plotdata = Max;
A=sortrows([Dir,plotdata]); % sorts into ascending order
Dir=A(:,1).*pi./180; % converts to radians from degrees
plotdata=A(:,2);
New=[];
for i=1:size(A(:,2),1)
New=[New;plotdata(i);plotdata(i)];
end
% plot the data
figure;
[t,r]=rose(Dir,720);
ind=find(r);
r(ind)=r(ind).*New';
p = polar(t,r,'b');
view([90 -90])
%patch('FaceColor','none');
%%Mean
clear A t r p i ind New plotdata
plotdata = Mean;
A=sortrows([Dir,plotdata]); % sorts into ascending order
Dir=A(:,1).*pi./180; % converts to radians from degrees
plotdata=A(:,2);
New=[];
for i=1:size(A(:,2),1)
New=[New;plotdata(i);plotdata(i)];
end
% plot the data
figure;
[t,r]=rose(Dir,720);
ind=find(r);
r(ind)=r(ind).*New';
p = polar(t,r,'g');
view([90 -90])

채택된 답변

Guillaume
Guillaume 2016년 1월 5일
It appears to me that there is an obvious bug. You have:
...
%%Max
plotdata = Max;
A=sortrows([Dir,plotdata]); % sorts into ascending order
Dir=A(:,1).*pi./180; % converts to radians from degrees
From then on, Dir is in radian. You then have:
%%Mean
...
A=sortrows([Dir,plotdata]); % sorts into ascending order
So, the first column of A is in radian. But you do on the next line:
Dir=A(:,1).*pi./180; % converts to radians from degrees
Which is obviously wrong.
However, I'm not sure it will be enough to solve your problem. I don't really understand what you are doing with your find and your repeating of your plotdata via New. Certainly, I don't see why the number of non-zero bins (number of elements in ind) should be twice the number of rows in data (= number of rows in New). So, I don't see how you can guarantee that r(ind).*New' work.
Incidentally, a much more efficient way of generating your New is with:
New = [plotdata'; plotdata'];
New = New(:); %no need for a loop

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by