How to use if-else in this scenario?

1 visualización (últimos 30 días)
Armando MAROZZI
Armando MAROZZI el 3 de Nov. de 2020
Respondida: Mathieu NOE el 3 de Nov. de 2020
I have a vector of numbers. What I would like to do is to change the composition of this vector depending on which function I am using.
Let me explain it in more details:
% this is the vector I have
t = [1; 1; 1; 5; 5; 5; 2; 5; 5]
% Now let's assume I have two functions x and y that take t as an argument.
% I would like to write a code that says t equals to the vector you see above in function x
% while for function y every element = 1 in t becomes 6
Can anyone help me do it?
Thanks!

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 3 de Nov. de 2020
hello Armando
I don't see what the first function is supposed to do ? output = input ? so what ?
for the second task, this should do the trick :
t = [1; 1; 1; 5; 5; 5; 2; 5; 5]
val1 = 1; % value to be replaced in t
val2 = 6; % value in replacement
output = Y(t)
% second function Y
function output = Y(input,val1,val2)
output = input;
ind = find(output==val1);
output(ind) = val2;
end

Más respuestas (0)

Categorías

Más información sobre Power and Energy Systems en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by