Nested If-ELSEIF statements
Ältere Kommentare anzeigen
I tried looking up this question in litreature and the forum and I couldn't find anything pertaining to my situation.
I have the following nested if-elseif statements, and I observed by using breakpoints, the code skips after processing the first if-elseif statement. It skips the caulations at the ellipsis too. I want it to run through the rest of the elseif and check the logic and calculate results - any help is appreciated
This excerpt is supposed to change the extreme points out of Nx and -Nx.
if X<-Nx
X=Nx;
elseif X>Nx
X=-Nx;
if Y<-Ny
Y=Ny;
elseif Y>Ny
Y=-Ny;
if Z<-Nz
Z=Nz;
elseif Z>Nz
Z=-Nz;
...
end
end
end
3 Kommentare
Bjorn Gustavsson
am 16 Jun. 2020
Bearbeitet: Bjorn Gustavsson
am 16 Jun. 2020
This seems to be a rather peculiar logic.
If X is smaller than -Nx then we set X to positive Nx. If X is between -Nx and Nx we do nothing, otherwise i.e. if X is larger than Nx we set X to -Nx and start to look at the condition for Y (which also has a do-nothing for Y-values between -Nx and +Nx).
Is this really the logic that you want?
...And this is not the way to write this if X Y or Z are arrays.
Hans123
am 16 Jun. 2020
Hans123
am 16 Jun. 2020
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 16 Jun. 2020
Without knowing the values of any of those variables? How are we supposed to do that? Can you attach them in a .mat file
save('answers.mat', 'X', 'Y', 'X', 'Nx', 'Ny', 'Nz');
But I'm sure it's going into, or skipping, whatever if/else block it's supposed to based on the variable values and nesting.
Do you want to do anything in the case that X is in the range [-Nx, Nx]? Currently that case is not handled.
Do you just want to clip values, like
X = min(X, Nx);
X = max(X, -Nx);
instead of all that if stuff?
Kategorien
Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!