Bold comments and if statements

52 views (last 30 days)
JP
JP on 4 Jul 2013
I am having this annoying problem where I want to break up a long if statement into multiple sections using bold comments so it looks nicer....at this point its almost not worth my trouble but hopefully one of you can help. Here is my code. You will probably have to put the code into MATLAB to see what I am talking about. The bold comments will not encompass certain sections of my if statement. Instead, they make their own mini-sections and then the whole if statement is still in one block. Please let me know if there is a way to somehow change the area the bold comment section covers manually or something like that. Thanks!
%%Provides four different cases depending on which combination of tools are in the viewing screen of Polaris Vicra
%For transformations between frames, the labels always begin with the
%original coordinate system which is being transformed, INTO the new
%coordinate system, marked by "_" in between the names, and after the two
%names will be the type of transformation being used
%Example 1: data.Endo_RefHomMat---(Homogeneous matrix giving transformation from endoscope's coordinate system to reference tool's coordinate system)
%Example 2: data.Endo_RefPosVec---(Position vector of the endoscope in the reference tool's coordinate system)
%Note: If a vector is given in four dimensions, it is just to aid calculations with homogeneous matrices; take the first three components
%Abbreviations:
%Endo---Endoscope
%Ref---Reference Tool
%Mat---Matrix
%HomMat---Homogeneous Matrix
%RotMat---Rotation Matrix
%Point---Pointer Tool
%PV---Polaris Vicra
%Vec---Vector
%Pos---Position of Tool
%Tip---Tool Offset Tip
%Offset position and orientation of tool tip, enter these values manually from NDI offset program for endoscope
data.OffsetEndoX=-51.94;
data.OffsetEndoY=-2.15;
data.OffsetEndoZ=-256.40;
data.OffsetEndoPsi=0;
data.OffsetEndoTheta=0;
data.OffsetEndoPhi=0;
data.Endo_TipHomMat=HomMatrix_Euler(data.OffsetEndoX,data.OffsetEndoY,data.OffsetEndoZ,data.OffsetEndoPsi,data.OffsetEndoTheta,data.OffsetEndoPhi);
%%Both tools are missing from the Polaris Vicras's screen %%
if isequal(datastr([5:11,31:37]), 'MISSINGMISSING' )
%Data in quaternions of endoscope
data.Q0=0;
data.Qx=0;
data.Qy=0;
data.Qz=0;
%Position of endoscope, rms error, port status and the frame number
data.Tx=0;
data.Ty=0;
data.Tz=0;
data.rmsError=0;
%%Endoscope is missing but reference tool is in Polaris Vicra's screen %%
elseif datastr(5:11)=='MISSING'
%Data in quaternions of endoscope
data.Q0=0;
data.Qx=0;
data.Qy=0;
data.Qz=0;
%Position of endoscope, rms error, port status and the frame number
data.Tx=0;
data.Ty=0;
data.Tz=0;
data.rmsError=0;
%%Endoscope is in view but reference tool is out of Polaris Vicra's screen
elseif datastr(75:81)=='MISSING'
data.Q0=str2double(datastr(5:10))/10000;
data.Qx=str2double(datastr(11:16))/10000;
data.Qy=str2double(datastr(17:22))/10000;
data.Qz=str2double(datastr(23:28))/10000;
data.Tx=str2double(datastr(29:35))/100;
data.Ty=str2double(datastr(36:42))/100;
data.Tz=str2double(datastr(43:49))/100;
data.rmsError=str2double(datastr(50:55));
data.Q02=0;
data.Qx2=0;
data.Qy2=0;
data.Qz2=0;
data.Tx2=0;
data.Ty2=0;
data.Tz2=0;
%%Both endoscope and reference tool are in Polars Vicra's screen
else
data.Q0=str2double(datastr(5:10))/10000;
data.Qx=str2double(datastr(11:16))/10000;
data.Qy=str2double(datastr(17:22))/10000;
data.Qz=str2double(datastr(23:28))/10000;
data.Tx=str2double(datastr(29:35))/100;
data.Ty=str2double(datastr(36:42))/100;
data.Tz=str2double(datastr(43:49))/100;
end
%%Plots position and gives vector showing orientation
figure(2)
%quiver3 gives direction the pointer/endoscope is pointing
quiver3(data.FinalOffsetPosition(1),data.FinalOffsetPosition(2),data.FinalOffsetPosition(3),35*data.EndoOrient(1),35*data.EndoOrient(2),35*data.EndoOrient(3),'r*');
hold on
%plot3 makes sure the reference tool is always positioned at (0,0,0) in its own frame
plot3(0,0,0,'b*');
xlim([-400 400]);
ylim([-400 400]);
zlim([-400 400]);
title('Position and Orientation of Endoscope');
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
drawnow
hold off

Accepted Answer

Matt J
Matt J on 4 Jul 2013
Edited: Matt J on 4 Jul 2013
I am having this annoying problem where I want to break up a long if statement into multiple sections using bold comments so it looks nicer
You might be misinterpreting the purpose of %%. It is not meant simply as a way of bold-fonting comments for appearance's sake. It is a way of designating code cells for the purpose of working in Cell Mode.
If you know this already, but you simply want the contents of each if/else block to have a cell of its own, bring the %% inside the body of the else, e.g.,
if isequal(datastr([5:11,31:37]), 'MISSINGMISSING' )
%%Both tools are missing from the Polaris Vicras's screen %%
....
It does not make sense to include an isolated if statement in a code cell, without its matching else...end, because such a block cannot run in isolation. That's why MATLAB doesn't let you do it.

More Answers (0)

Categories

Find more on View and Analyze Simulation Results in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!