Format Issues - will not accept a character or a double
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I'm having another really basic problem.
I want to use a different source for each plant, but it really doesn't like the format.
I get an error message at Xsource saying undefined function X_src_ for function of double or character if I change it. Am I missing something quite obvious?
Any help/advise is very much appreciated!
for plant = 1:5
Xsource = x_src_(num2str(plant));
Ysource = y_src_(num2str(plant)) ;
X_shft = X_rot - x_src_(Xsource);
Y_shft = Y_rot - y_src_(Ysource);
[i] = find(X_shft > 0);
0 Kommentare
Antworten (2)
Thorsten
am 25 Sep. 2015
It would be helpful to know 1) what you want to achieve in your code and 2) how are the variables defined, like x_src_c, X_rot, Y_rot etc.
In particular, what is x_src_? You can check using
whos x_src_
Regardless of what x_src_ actually is, it you try to index into x_src_ using a string, e.g., '1' by using num2str(plant)). That seems strange to me. What do you want to achieve in this line of code?
2 Kommentare
Thorsten
am 25 Sep. 2015
Do you mean like this?
for plants = -20000:10000:20000
Xsource = plants; Ysource = plants;
% further code here
end
or if you insists on the order of the plants
for plants = [0 10000 -10000 20000 -20000]
Xsource = plants; Ysource = plants;
% further code here
end
Guillaume
am 25 Sep. 2015
From your comment it looks like you're trying to index different variable names depending on a condition. The answer to that is very simple: DO NOT DO THAT. In matlab or any other language.
Create an array and index into this array
X_src = [0, 10000, -10000, 20000, -20000];
Y_src = [0, 10000, -10000, 20000, -20000];
for plant = 1:5
Xsource = X_src(plant);
Ysource = Y_src(plant);
%...
end
Using numbered variables is very poor practice. There are many posts on this forum and a lengthy explanation in the faq detailing why.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Control System Toolbox 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!