开发者

Inserting multiple links into an image in Matlab?

开发者 https://www.devze.com 2023-03-26 01:08 出处:网络
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 cod

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:

  1. the file() function doesn't know the values of x and y
  2. the file() function doesn't use the current value of i
  3. the file path uses x(1) idependently of the value of i

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号