How to use variable in a function?
古いコメントを表示
Hello. I am trying to make a function which will take strings as input (where string contains 3 characters: 0, +, -) and any '+' or '-' character will be replaced by '0'.
Now i want to add a variable which determines how many '+' or '-' will be replaced by '0'. But i am not getting any idea how to add it in the function. I want to add this variable because input_strings and working_variable will be changing continously. Following is my code:
function replacement_result = replacement(input_strings, working_variable)
for i1 = 1 : size(input_strings,1)
a = 0;
for j1 = size(input_strings,2): -1 : 1
if input_strings(i1,j1) == '0';
a = a+1;
else break,
end
end
for k1 = (size(input_strings,2)-a): -1 : 1
if input_strings(i1, k1) ~= '0'
input_strings(i1, k1) = '0';
else break,
end
end
end
replacement_result = input_strings;
If input_strings = [0+0-00-0+, +0+0-0+0-, -0-00-0+0], then if working_variable = 1, so replacement_result = [0+0-00-00, +0+0-0+00, -0-00-000]
If input_strings = [0+0-00-0+, +0+0-0+0-, -0-00-0+0], then if working_variable = 3, so replacement_result = [0+0000000, +0+000000, -00000000]
How can i add 'working_variable' in this function? Can any one please give me any idea?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!