How to list specific variable at all points except at certain values

I am currently writing a code where I am trying to figure out how to program a certain value for all inputs except at certain values. For example, if I am running trials starting at 0 and ending at 10, and would like an output of 5 for trails 0-4, and an output of 10 for all others, how would I go about coding that? And if possible, can it be set up to where all outputs do not need to manually be written, so if I decide to run more trials (either before 0 or after 10) it will autofill the new slots? Thanks for the help

Respuestas (1)

I have no idea what the actual application is.
One option:
outpt = @(trial) ((trial >= 0) & (trial <= 4)).*5 + ((trial < 0) | (trial >= 5))*10;
x = -5:15;
figure
stem(x, outpt(x), 'filled')
grid
axis([-5.5 10.5 -0.5 10.5])
xlabel('Trial')
ylabel('Output')
Experiment to get the desired results.
.

6 comentarios

In this case, the actual application is stimulus application of voltage. A voltage is applied for X seconds, during which it has a current of Y. For any times before/after the stimulus, the current is now Z. I've been trying to write it as an If/Else statement such that if, say, a stimulus is applied for X seconds, it has an output of Y when measured sampled during X, otherwise the output is Z. for example, the code I'm writing is
StimAmp = 200
StimDur = 0.15
tNow = (0:.05:.5)
if(0<= tNow & tNow <=StimDur)
Jm = StimAmp;
else
Jm = 0;
end
where in this case ay time between and including 0-.15 seconds has an output of 200, and the output of any time before 0 seconds or after .15 seconds is 0. The script 'works' but only has an output of what StimAmp/StimDur are defined as, and listing the values of tNow in columns without displaying what the actual outputs are.
I am slightly lost.
I don’t understand ‘X’, ‘Y’, and ‘Z’.
I would appreciate an example record (can be synthetic so long as it represents the desired stimulus) and the desired result. Is the on-off time important, so that the function would have to test for the time length (or any other parameters) as well as amplitude, or is the amplitude threshold itself the only parmeter-of-interest?
.
The X/Y/Z thing was just my unfortunatetly less-than-helpful 'explaination' of this problem. Using this picture as an example, I'm trying to figure out how to get the values of the 3rd column (Is) to be 200 at any time between 0 and .15 seconds, and 0 at all others. The on off time is important since all other values in the chart are dependant on the value of Is.
No worries.
Unfortuantely, that’s an image and I would prefer to work with text that I can save to a file (if necessary) and work with. If it would be possible to save that as a table, that would be really helpful.
Also, it would be helpful to have the variable names (column headers) translated into something meaningful. (I’m a native English speaker with an M.D., and an M.S. in Biomedical Engineering, however ‘ioopent’, ‘Is’, ‘Vm’, ‘vdot’, ‘n’, ‘m’, and ‘h’ could be anything. I have no idea how they relate to this probllem.)
.
I wish I had a test version of this table, but it is unfortately a screenshot from my textbook of what the output should look like. I understand the math behind what's going on and how to do this pencil/paper, but an having difficulty getting the script to work. The example script provided to us is saying that the input should look like this:
if( 0<=tNow && tNow<StimDur ) % start stimulus current at tNow=0
Jm = Jstim ;
else % stop stimulus when tNow = StimDur
Jm = 0 ;
but trying to run it this way is only producing the timestep values of (0:.05:.5), but not with the output value of 0 or 200. These are for the 'Is' coulumn. As for the ‘ioopent’, ‘Vm’, ‘vdot’, ‘n’, ‘m’, and ‘h’ coulumns, those are working when testing them with manually inputted values, but actually rely on the Is value to be computed for a whole script (for example values of the Vm coulumn are calculated as Vm_previous - (Is-X)*.05).
I apologise, however this isn’t helpful.
I understand that you may understand the textbook description, however I don¹t. I’m still having a difficult time understanding both the input and the desired output.
Is there a way for you to download the data from the textbook website online and post it here with an explanation of what it is and what the desired output should be from it?
Just now, I don’t have a clue.
I would very much like to help, however I need more definitive information.
.

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 12 de Dic. de 2021

Comentada:

el 12 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by