Running a calculation for an entire array and putting the results into a new array

48 Ansichten (letzte 30 Tage)
Hello
I am trying to write code to run a calculation using the values in an array and storing them in a new array.
For example:
I have the array A, that has 194 values.
I want to use a calculation like: 2+2/n = c, with n being the number in the array and to store the answer, c, in array B.
I code use some help on the code, I don't know if it needs a for loop.
Thanks

Akzeptierte Antwort

Erivelton Gualter
Erivelton Gualter am 20 Nov. 2019
Bearbeitet: Erivelton Gualter am 20 Nov. 2019
% Given A as:
A = 1:194;
% We can simply solve the following:
B = 2+2./A;
  2 Kommentare
Paul Torres
Paul Torres am 20 Nov. 2019
Of course its this simple and I spent too much time on it. Thank you
Owen Brady
Owen Brady am 21 Apr. 2023
How would I do an equation where the array is angles and must be in a cos and sin function?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by