While function for finding the checking each elements in a vector of unknown length

Hello,
I am given a question to change the size of each elements in a vector. However, I don't know how to use a loop function like while function and if else function to check the sizes of each elements in the vector.
Can someone please help me solve this problem?
e.g. A = [44,55,24,63,74,76,55,87];
Determine whether each element in vector A is larger than 70, and if it is, subtract 10 and place the new value back to the vector. (its not the actual question. just made it up)
in this case, how do I create a function that checks each value and places the new value back to the vector?
Thank you.

1 件のコメント

James Tursa
James Tursa 2019 年 9 月 21 日
編集済み: James Tursa 2019 年 9 月 21 日
What have you done so far? What specific problems are you having with your code? Do you know how to write a function? Do you know how to write a loop? Do you know how to write an if-test? Do you know how to use indexing?

回答 (1 件)

David Hill
David Hill 2019 年 9 月 21 日
A-10*(A>70);

1 件のコメント

madhan ravi
madhan ravi 2019 年 9 月 21 日
Obviously it's homework. Giving hints is preferred rather than providing the complete solution.

この質問は閉じられています。

質問済み:

2019 年 9 月 21 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by