matrix operation to scalar
6 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
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)
butterForRecipe1 = stickOfbutter(1:7);
stickOfbutter(1:7) = [] % I used 7 tablespoons for recipe 1
butterForRecipe2 = stickOfbutter(1:2) % Error, not enough
0 Comments
More Answers (0)
See Also
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!