![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1156378/image.png)
Index in position 1 is invalid Problem
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
clear all
close all
clc
h = input('Enter the step size: '); %240
tf = input('Final Value: '); %480
t = 0:h:tf
th = zeros(1,length(t))
th(1) = input('Enter the initial value: '); %1200
fun = input("Enter the function with respect to th: "); %((-2.2067.*(10.^-12)).*((th.^4)-(81.*10^8)))
k_1 = fun(t(1), th(1))
Dear altruist,
This is my code, but it tells me that: "Index in position 1 is invalid. Array indices must be positive integers or logical
values."
Kindly help me with this.
0 Kommentare
Antworten (1)
Eric Delgado
am 14 Okt. 2022
Try this...
x = [0,240,480];
y = [1200,0,0];
Fcn_AddThings = str2func('@(x,y) x.^2 - 2*y');
Fcn_AddThings(x, y)
Fcn_AddThings(x(1), y(1))
Looking at your example, you can replace str2fun for input - see the image below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1156378/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!