How to overcome error Matrix dimenssioms Must Agree?
Mostra commenti meno recenti
Dear All,
I am new to Matlab and I am attempting to edit a pre existing script, from the script I am reading a Inertial data varialble which is a dynamic matrix of size 6*(nr_bytes/34). I want o read the last three rows of matrix and synchronize it with the cylinder coordinates.
% Clear workspace
clear all, clc, close all
% Open serial port
com = serial('COM6');
fopen(com);
% Open binary file for saving inertial data
filename = 'imu_data.bin';
file = fopen(filename, 'w');
% Flush serial ports
while com.BytesAvailable
fread(com,com.BytesAvailable,'uint8');
end
% Request combined inertial readings in SI-units
header = 64; % 64 = no online bias estimation, 65 = online bias estimation
rate_divider = 4;
command = [header rate_divider];
command = [command (sum(command)-mod(sum(command),256))/256 mod(sum(command),256)];
fwrite(com,command,'uint8');
fread(com,4,'uint8')
% Open dummy figure with pushbutton such that logging can be aborted
abort = 0;
figure;
uicontrol('style','push','string','Stop','callback','abort=1;');
drawnow
% Logg data until pushbutton pressed
nr_bytes = 0;
while abort==0
if com.BytesAvailable>0
nr_bytes = nr_bytes + fwrite(file,fread(com,com.BytesAvailable,'uint8'),'uint8');
end
drawnow
end
% Stop output
fwrite(com,[34 0 34],'uint8');
fread(com,4,'uint8')
% Close serial port and file
close;
fclose(com);
fclose(file);
% Parse data and delete logging file
[inertial_data,time_stamps,raw_data]=parse_imu_data(filename);
%delete(filename);
myaxes = axes('xlim',[-1,1],'ylim',[-1,1],'zlim',[-1,1]);
view(3);
%grid on;
axis equal;
hold on
xlabel('X')
ylabel('Y')
zlabel('Z')
[xcylinder ycylinder zcylinder] = cylinder([0.25 0.25]);
h = surface(xcylinder,ycylinder,zcylinder,'FaceColor', 'green');
x = (inertial_data(4:4,:));
y = (inertial_data(5:5,:));
z = (inertial_data(6:6,:));
xcylinder = x;
ycylinder = y;
zcylinder = z;
h = surface(xcylinder,ycylinder,zcylinder,'FaceColor', 'green');
I am getting a error
Error using surface
Matrix dimensions must agree.
Error in NORMAL (line 88)
h = surface(xcylinder,ycylinder,zcylinder,'FaceColor', 'green');
Nikhil Singh
2 Commenti
Stefan Raab
il 21 Ott 2015
Hello Nikhil, I think the function surface needs some matrix inputs (see doc surface). You're calling it with only vector-data. Kind regards, Stefan
Nikhil Singh
il 21 Ott 2015
Risposte (1)
Bjorn Gustavsson
il 21 Ott 2015
0 voti
Your arrays xcylinder, ycylinder and zcylinder are 1-D, and surface expects 2-D arrays, to reformat your x,y,z into 2-D you have a number of possibilities.
- The points in x and y fill up a nice regular grid of some sort.Then just reformat the matrices into 2-D arrays where you put points where they logically belong.
- The points in x and y does not fill up anything nearly like a regular grid or are completely unorganized. Then you'd better turn to any of the triangulation functions of matlab: delaunay, scatteredInterpolant, TriScatteredInterp, triangulation, and for rather direct plotting of the triangulated surface: trisurf.
HTH
1 Commento
Nikhil Singh
il 21 Ott 2015
Categorie
Scopri di più su Geographic Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!