Effacer les filtres
Effacer les filtres

How to use if-else in this scenario?

1 vue (au cours des 30 derniers jours)
Armando MAROZZI
Armando MAROZZI le 3 Nov 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!

Réponse acceptée

Mathieu NOE
Mathieu NOE le 3 Nov 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

Plus de réponses (0)

Catégories

En savoir plus sur Power and Energy Systems dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by