Is it possible to incorporate a hyperlink within a string array that references a specific variable while in a for loop
19 views (last 30 days)
Show older comments
Hello, I currently am writing a code that deals with the use of hyperlinks in MATLAB. I currently have a for loop that will set up a string array description. I would like this string array description to have a hyperlink in it that is associated with a specific variable that gets referenced in the for loop. In other words, when the hyperlink is clicked on, I would like the specific variable that was correlated with the specific for loop "i" value to be input into a function. The code below shows my attempt. As you can see I have a "names" vector with 3 names, and I would like the "descrip" array to have a hyperlink that allows me to run function "infoget" using a specific name (depending on the for loop iteration). I was hoping that the "descrip" array would store so that if I wanted the information associated with bob that would be in the "descrip{:,1}" position. So it becomes just a matter of calling that out, and clicking on the link.
names = ['bob' 'james' 'jim'];
for i = 1:length(names)
descrip{:,i} = sprintf('%s<br>%s</br><br>',...
'The link below will bring up the following information for a specific name',...
'<a href="matlab: infoget(%s) ">Information</a>',names{i});
end
0 Comments
Answers (2)
the cyclist
on 17 May 2018
Your code will at least execute if you change
names = ['bob' 'james' 'jim']
to
names = {'bob' 'james' 'jim'}
Is that enough for you to see your way clear for any other corrections?
1 Comment
Christopher Martinez
on 17 May 2018
Edited: Christopher Martinez
on 17 May 2018
the cyclist
on 17 May 2018
Edited: the cyclist
on 17 May 2018
I haven't figured out what you were trying to do with the breaks, but the core functionality works if you use this:
descrip{:,i} = sprintf('The link below will bring up the following information for a specific name: <a href="matlab: infoget(%s) ">Information</a>',names{i})
The main problem with your version (as I understand it), is that you were trying to put a formatSpec into the second argument of the sprintf. That won't work (unless maybe you nest another sprintf command, but I don't think you need to do that).
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!