ans = 
Vector with symbolic variable
古いコメントを表示
I have created a 8x1 sym (vector?) called psi and a 1x1000 double (vector?) called time. When I try to plug in a value from the double into the psi I use the syntax:
psi_eval = psi(time(2));
since this is the way I would have done it in python, however it does not work. I get an error saying:
Array indices must be positive integers or logical values.
Error in sym/subsref (line 909)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in BachelorThesis (line 65)
psi_eval = psi(time(2));
The array index I have given is a positive value so I don't understand the error I get. What am I doing wrong?
採用された回答
その他の回答 (2 件)
Walter Roberson
2024 年 5 月 4 日
編集済み: Walter Roberson
2024 年 5 月 4 日
Your time vector contains at least one value that has a fraction or is not a positive value.
For example, your time vector might start from 0, or might increment by 1/10th of a second.
mask = find(time ~= floor(time) | time <= 0);
if isempty(mask)
fprintf('times check out okay!\n');
else
fprintf('invalid times!\n');
disp(compose("index %03d, value %g", mask(:), time(mask)));
end
Works for me.
psi = sym('psi',[8 1]);
t = 1:1000;
psi(t(5))
2 件のコメント
Lilted
2024 年 5 月 4 日
Why not show a simple, but complete, example that makes shows the full code, in partcular the defintion of psi, and clearly shows what you're trying to do? As it stands, we can only guess. Maybe something like this:
syms t
psi = [t;2*t];
time = rand(1,2000);
subs(psi,t,time(2))
vpa(ans)
[time(2);2*time(2)]
カテゴリ
ヘルプ センター および File Exchange で Code Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

