Format Issues - will not accept a character or a double
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Thorsten
2015년 9월 25일
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
Thorsten
2015년 9월 25일
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
2015년 9월 25일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!