Borrar filtros
Borrar filtros

Click on row in TextArea?

9 visualizaciones (últimos 30 días)
Kurt
Kurt el 4 de En. de 2023
Comentada: Walter Roberson el 5 de En. de 2023
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

Respuesta aceptada

Kurt
Kurt el 5 de En. de 2023
The "compose" approach reduced the formatting from about 7 minutess to 10 seconds. Thanks!
I solved the TextArea size issue by leaving the 16-column TexArea alone, and creating a separate UITable off to the side containing just the first column of the TextArea - in effect, a "spinbox" containing text, not numbers. I can scroll through it and pick the appropriate line by clicking.

Más respuestas (1)

Walter Roberson
Walter Roberson el 4 de En. de 2023
Editada: Walter Roberson el 4 de En. de 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 comentarios
Kurt
Kurt el 5 de En. de 2023
Thanks. I'll try that.
Back to the performance issue: Is there a method to apply a full-blown function to an entire column without looping? I run into this a lot. I've done the simple one-liner, inline functions on a whole column, but I need something more. For example, the code to convert azimuth to right ascension is about 50 lines long. Is this possible?
Walter Roberson
Walter Roberson el 5 de En. de 2023
arrayfun.... but it is just a hidden loop, and you are better off vectorizing the code, possibly using logical indexing.

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by