matrix operation to scalar
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Selim Elbadri
el 27 de Ag. de 2022
Respondida: Steven Lord
el 27 de Ag. de 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 comentarios
Respuesta aceptada
Steven Lord
el 27 de Ag. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!