How to Compare a vector with for loop iterations in a nested if statement in a for loop
Show older comments
I'm trying to write a nested if statement within a for loop, where I compare a user input vector of numbers (1,2,3,4,etc.) to the iterations of a for loop (e.g. for i=1:length(a vector)). I need to compare each iteration of the for loop with the user input vector of values, and if they match, the code will return a certain equation; if not, the code will return a different equation. Ultimately, I need a column vector of equations based on the if/for loop. Any thoughts?
function [ DeltaO2Concentration ] = O2Solver_beta(t,O2Conc,c,O2Leak_term,Num_nodes)
%UNTITLED Test function used to solve 'first attempt' code.
% System of ODE diffusion equations that will be solved using 'ode45'
% function. Inputs are constant composed of universal and calculated
% constants, time (independent variable), O2Conc (dependent variable),
% O2Leak which is a separate term or something.
%VECTOR LENGTH WILL NEED TO VARY ACCORDING TO USER INPUT%
start= 0;
terminate= Num_nodes;
DeltaO2Concentration= zeros(1,terminate-start); %Initialize Vector
cnt= 1;
for i= 3:length(DeltaO2Concentration)
if %THE ITERATION MATCHES A VALUE IN THE USER INPUT VECTOR
%RETURN EQUATION 1
ifelse
%RETURN EQUATION 2
end
cnt= cnt+1;
end
DeltaO2Concentration= DeltaO2Concentration';
end
Here is the main script, for reference
prompt_node= {'Enter Selected Node Numbers (e.g. 1,2,3,4,...)'};
dlog_title= 'User Input';
answer_nodes= inputdlg(prompt_node, dlog_title);
Slt_nodes= strsplit(answer_nodes{1},',');
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differential Equations 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!