Azzera filtri
Azzera filtri

problem in code voxel

2 visualizzazioni (ultimi 30 giorni)
samer mahmoud
samer mahmoud il 17 Dic 2015
Risposto: Geoff Hayes il 17 Dic 2015
function voxel(i,d,c,alpha);
%VOXEL function to draw a 3-D voxel in a 3-D plot
%
%Usage
% voxel(start,size,color,alpha);
%
% will draw a voxel at 'start' of size 'size' of color 'color' and
% transparency alpha (1 for opaque, 0 for transparent)
% Default size is 1
% Default color is blue
% Default alpha value is 1
%
% start is a three element vector [x,y,z]
% size the a three element vector [dx,dy,dz]
% color is a character string to specify color
% (type 'help plot' to see list of valid colors)
%
%
% voxel([2 3 4],[1 2 3],'r',0.7);
% axis([0 10 0 10 0 10]);
%
% Suresh Joel Apr 15,2003
% Updated Feb 25, 2004
switch(nargin),
case 0
disp('Too few arguements for voxel');
% return;
case 1
l=1; %default length of side of voxel is 1
c='b'; %default color of voxel is blue
case 2,
c='b';
case 3,
alpha=1;
case 4,
%do nothing
otherwise
disp('Too many arguements for voxel');
end;
x=[i(1)+[0 0 0 0 d(1) d(1) d(1) d(1), ...
i(2)+[0 0 d(2) d(2) 0 0 d(2) d(2), ...
i(3)+[0 d(3) 0 d(3) 0 d(3) 0 d(3)];
for n= 1:3
if n==3
x=sortrows(x,[n,1]);
else
x=sortrows(x,[n n+1]);
end;
temp=x(3,:);
x(3,:)=x(4,:);
x(4,:)=temp;
h=patch(x(1:4,1),x(1:4,2),x(1:4,3),c);
set(h,'FaceAlpha',alpha);
temp=x(7,:);
x(7,:)=x(8,:);
x(8,:)=temp;
h=patch(x(5:8,1),x(5:8,2),x(5:8,3),c);
set(h,'FaceAlpha',alpha);
end;
i have a problem in boucle for
Error: File: Untitled.m Line: 47 Column: 1
Illegal use of reserved keyword "for".
  1 Commento
jgg
jgg il 17 Dic 2015
Your error does not look like it's in the voxel function: Error: File: Untitled.m Line: 47 Column: 1 Illegal use of reserved keyword "for".
I suggest looking at line 47 of your file and seeing if you used for incorrectly.

Accedi per commentare.

Risposte (1)

Geoff Hayes
Geoff Hayes il 17 Dic 2015
samer - you are missing a couple of square brackets in the line of code that precede the for loop. Look closely at the line
x=[i(1)+[0 0 0 0 d(1) d(1) d(1) d(1), ...
i(2)+[0 0 d(2) d(2) 0 0 d(2) d(2), ...
i(3)+[0 d(3) 0 d(3) 0 d(3) 0 d(3)];
There are four open square brackets, [, but only one closing one, ]. Why have you included all of these brackets? What is the intent behind this line of code?

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by