matrix operation to scalar
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Selim Elbadri
le 27 Août 2022
Réponse apportée : Steven Lord
le 27 Août 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!
0 commentaires
Réponse acceptée
Steven Lord
le 27 Août 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!