2011-08-05 25 views
1

这个问题是建立在此前一个问题'here'我想在图像上制作256个点,所有这些导致基于*位置的不同pdf文档。我不想在256个独立的文件路径中编码。我已经尝试了下面的一些代码,至今还没有运气。在Matlab中插入多个链接到图像中?

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 

回答

1

在我看来,你的代码是错误的几个地方:

  1. file()功能不知道x价值观和y
  2. file()功能不使用的电流值i
  3. 文件路径使用idependently的i
值的

您可能想要

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 
1

假设X(i)和Y(I)为整数,这应该工作:

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 

如果不是整数,你需要指定浮点数如何转换到一个字符串。你可以用num2str的第二个参数来做到这一点,输入:

help num2str 

了解详情并从那里浏览。