How to use if-else in this scenario?

1 次查看(过去 30 天)
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!

采纳的回答

Mathieu NOE
Mathieu NOE 2020-11-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Power and Energy Systems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by