MATLAB Answers

trying to put 2 numbers in the a single array repeated the same amount of times and get a sum that adds both of them up

2 views (last 30 days)
Alan Farah
Alan Farah on 11 Sep 2021
Edited: the cyclist on 11 Sep 2021
I have to create a single array of 512 elements, where the first 256 elements are all 0.9 and the last 256 elements are all 2.3, then i have to calculate the sum, but i have no idea how to do that. i am not looking for answers to my question, just for tips on how something like that should look like, since ive tried multiple different ways of solving this but end up with an incorrect sum.

Answers (1)

the cyclist
the cyclist on 11 Sep 2021
Edited: the cyclist on 11 Sep 2021
There are several ways to do this in MATLAB. Take a look at the repmat and repelem functions.
If you get the array defined correctly, I think the summing part should be easy.
Also, you might want to go through the MATLAB Onramp tutorial, which will teach some of the basics of MATLAB operations.



Community Treasure Hunt

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

Start Hunting!