matrix operation to scalar

1 view (last 30 days)
Selim Elbadri
Selim Elbadri on 27 Aug 2022
Answered: Steven Lord on 27 Aug 2022
Hi,
I have an operation c(t,1)/a(t,1) which takes as inputs an element from both a c and a vector. The output of this operation is a number. I would like to save this number as a scalar for the rest of the code. How can I do this? When I type in:
c = c(t,1)/a(t,1)
I get the following:
"Index in position 1 exceeds array bounds. Index must not exceed 1."
Thanks a lot!

Accepted Answer

Steven Lord
Steven Lord on 27 Aug 2022
Don't overwrite your vector variable with a scalar value then attempt to use it as though it were still a vector.
If you have a stick of butter (usually 8 tablespoons) and you use 7 tablespoons of it, you can't then use 2 tablespoons from that same stick. You don't have enough.
stickOfbutter = ones(1, 8)
stickOfbutter = 1×8
1 1 1 1 1 1 1 1
butterForRecipe1 = stickOfbutter(1:7);
stickOfbutter(1:7) = [] % I used 7 tablespoons for recipe 1
stickOfbutter = 1
butterForRecipe2 = stickOfbutter(1:2) % Error, not enough
Index exceeds the number of array elements. Index must not exceed 1.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!

Translated by