Click on row in TextArea?
Show older comments
I have a GUI that contains a TextArea. I read in a file that is 20,000 x 16 and convert each row to a string, so the resulting table is 20,000 x 1. Then I read that new "fits_text" table into the TextArea and use a formatSpec string to display it in neat columns, using tabs.
fits.TextArea.Value = fits_text;
So far, so good. Is there a way to click on a row of the text and determine which row it was, so I can process the data at that row in my original table (which is 20000 x 16)? Or do I need to use a UITable instead? I'm not sure I can fit a 16-column UITable into this GUI window.
Bonus question: It takes me about 7 minutes to re-format all 20,000 rows for display, using a "for" loop. I am pre-allocating space for the table. There must be a faster way. I can do this in Python in just a few seconds (but it doesn't look nearly as nice).
for i = 1:height(box_data)
fits_text{i,1} = sprintf(formatSpec, string(box_data{i,:}));
end
Accepted Answer
More Answers (1)
Walter Roberson
on 4 Jan 2023
Edited: Walter Roberson
on 4 Jan 2023
Unfortunately, TextArea do not have any selection callbacks; https://www.mathworks.com/help/matlab/ref/matlab.ui.control.textarea-properties.html
For the performance issue: use https://www.mathworks.com/help/matlab/ref/table.convertvars.html to build a new table from converting the existing variables to string. Then if you
fmt = [repmat('%s ', 1, 15), '%s'];
fits_text = compose(string(fmt), Table_Of_Strings{:,:});
This should, in theory, be higher performance.
If you wanted more careful control over the conversion of items into string then
fits_text = compose("Detailed % formats", box_data{:,1}, box_data{:,2}, box_data{:,3} ... box_data{:,16})
an uglier command line to be sure, but it gives per-item control like %6.2f and %-10s
2 Comments
Kurt
on 5 Jan 2023
Walter Roberson
on 5 Jan 2023
arrayfun.... but it is just a hidden loop, and you are better off vectorizing the code, possibly using logical indexing.
Categories
Find more on Develop Apps Using App Designer 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!