Error using .* matrix dimensions must agree
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jenny
el 5 de En. de 2016
Comentada: Jenny
el 5 de En. de 2016
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])
0 comentarios
Respuesta aceptada
Guillaume
el 5 de En. de 2016
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!