How can I write these formula in matlab ?
Show older comments
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
Jan
on 20 Mar 2018
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.
Answers (2)
Hassan Al-Khateeb
on 20 Mar 2018
Edited: James Tursa
on 20 Mar 2018
0 votes
2 Comments
Image Analyst
on 20 Mar 2018
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().
Hassan Al-Khateeb
on 21 Mar 2018
Edited: Hassan Al-Khateeb
on 21 Mar 2018
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!