matlab.ui.control.Table append column to new line of text file with space delimiters

3 views (last 30 days)
Hi Guys,
I really need help with this.
I have a UITable in App Designer with 3 columns. Column 1 contains a counter for the number of rows, column 2 contains a number between 100 and 500, and column 3 contains a decimal number between 0 and 1.
I need to get the contents of column 2 and append it in a new line of a text file in a row with space delimeters. For example:
Text File:
196 196 294 294 329 329 294 262 262 247 247 220 220 196 294 294 262 262 247 247 220 294 294 262 262 247 247 220 196 196 294 294 329
247 247 262 294 294 262 247 220 196 196 220 247 247 220 220 247 247 262 294 294 262 247 220 196 196 220 247 220 196 196 220 220 247 196 220 247 262
Text file after appended data from column 2:
196 196 294 294 329 329 294 262 262 247 247 220 220 196 294 294 262 262 247 247 220 294 294 262 262 247 247 220 196 196 294 294 329
247 247 262 294 294 262 247 220 196 196 220 247 247 220 220 247 247 262 294 294 262 247 220 196 196 220 247 220 196 196 220 220 247 196 220 247 262
220 196 294 220 247 247 196 220 220 247 196 247 247 262
I also need to do the same thing for column 3 aswell, I imagine the code will look very similar.
Thank you so much for your help.

Accepted Answer

Krishna Zanwar
Krishna Zanwar on 7 Feb 2019
Lets say the handle of your UI table is uit,
To get ui table data
D=get(uit,'Data');
Now you have the data from the table in variable ‘D’
fileId=fopen('krishna.txt','w') %to create a new text file
fprintf(fileId,'\n');
fprintf(fileId,'%d',D(:,3)); %To print third column
  1 Comment
George Aiken
George Aiken on 10 Feb 2019
Got it thank you so much. I ended up saving to a excel file using dlmwrite and then importing it from an excel file as a matrix, then saving to the excel file. But thank you for the solution, I will keep in mind going forward, I find matlab documentation rather cumbersome.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!