This question is built off of this previous question 'here'
I want to make 256 points on the image that all lead to different pdf documents based on the location of the *. I dont want to have to code in 256 separate filepaths. I have attempted some code below and have not been having any luck so far.
for i = 1:256
text(x(i),y(i),'*', 'ButtonDownFcn',['open(''' file ''');']);
end
function [filePath] = file()
%h = impoint;
%position = getPosition(h);
filePath =开发者_如何学编程 strcat('C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_',x(1),'-',y(i),'.pdf');
end
It seems to me that your code is wrong in several places:
- the
file()
function doesn't know the values ofx
andy
- the
file()
function doesn't use the current value ofi
- the file path uses
x(1)
idependently of the value ofi
You probably want
for i = 1:256
text(x(i), y(i), '*', 'ButtonDownFcn', ['open(''' file(x(i),y(i)) ''');']);
end
function [filePath] = file( x, y )
filePath = strcat('C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_',x,'-',y,'.pdf');
end
Assuming x(i) and y(i) are integers, this should work:
prefix = 'C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_'
for i = 1:256
filePath = [prefix num2str(x(i)) '-' num2str(y(i)) '.pdf'];
text(x(i),y(i),'*', 'ButtonDownFcn',['open(''' filePath ''');']);
end
If they aren't integers, you need to specify how the floating point number will be converted to a string. You can do that with the second argument of num2str, type:
help num2str
for details and browse from there.
精彩评论