How can I write these formula in matlab ?

Hi, In this scenario, I have values from 1 to 100
RegdIg=[RegdIg1;RegdIg2;RegdIg3;RegdIg4;RegdIg5;RegdIg6;RegdIg7;RegdIg8; ................. ,RegdIg100] gs=gs1+gs2+gs3+gs4+gs5+gs6+.................+gs100
How can I write these formulas in matlab ?

1 Comment

The question is not clear. Do you have a bunch of variables called "gs1", "gs2", ...? If so, this is a really bad idea. Use one variable instead as a vector. Then summing up works by the sum() command.

Sign in to comment.

Answers (2)

Hassan Al-Khateeb
Hassan Al-Khateeb on 20 Mar 2018
Edited: James Tursa on 20 Mar 2018
Dear Mr.Jan,
Let me explain this for you.... Actually, we have (100) clusters ..... we have gs1 & RegdIg1 for cluster number(1) In the same way, we have gs2 & RegdIg2 for cluster number(2)....... .....gsn & RegdIgn for cluster number(n), where gs is equal to the sum of the gs in all clusters that's mean gs=gs1+gs2+ ......+gsn RegdIg is a matrix , where RegdIg=[RegdIg1;RegdIg2;.......;RegdIgn].
How can I write these formulas in Matlab ?

2 Comments

You just have to do it like you did
gs=gs1+gs2+ ......+gs100;
RegdIg=[RegdIg1;RegdIg2;.......;RegdIg100]
Yeah, not fun to have to write it down a hundred times, but you made your bed so you now have to lie in it. Or you can not create those variables in the first place, and use an indexed array like everyone is telling you to. Then it's a simple for loop or a call to sum().
both gs & RegdIg are having different formulas . How can I calculate all the values of (gs) as sum of all gs in the clusters ....gs=gs1+gs2+ ......+gs100;
and in the same way. how can I put.each value of RegdIg as a matrix RegdIg=[RegdIg1;RegdIg2;.......;RegdIg100];

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 20 Mar 2018

Edited:

on 21 Mar 2018

Community Treasure Hunt

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

Start Hunting!