check a condition once and remember it later in the code
Show older comments
I want to check for an input at the beginning of my code.
then when i enter a while loop i don't want to recheck this input,
i want to already know it to save time. for example
function [ W,H,T] = AS_R(Q, X,W,H,options)
% first check
if strcmp(options.type, 'RSI')
[ L,R,X_R,X_L ] = RSI(X,r);
elseif strcmp(options.type, 'GC')
[ L,R,X_R,X_L ] = GC(X,r,nu);
else
disp('Compression type does not exit');
end
while (toc<= options.Tmax)
for i=1:20
%do something
end
% Do Something
%--------MY QUESTION ------------------___%
% At this point i obtain new values, and so i need to call my function
% that i checked for in the beginning but dont want to do the strcmp checks again
% I want matlab to already know my choice from the first instance
[ L,R ,X_R,X_L ] = RPI(X,r); % eg it should already use the RSI since it picked it from start.
k=k+1;
end
end
Accepted Answer
More Answers (1)
Categories
Find more on Loops and Conditional Statements 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!