Matlab Appdesigner Saving Data to Text File

% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
app.t.Thrust(1) = str2num(app.SaveButton);
fileid = fopen ('C:\**\**\**\**\***\**\****.txt')
Error using str2num (line 35)
Input must be a character vector or string scalar.
The above is the code giving me the problem.
I am just trying to save one number from my data to a text file and I got the above error.
Is there an alternate command to proceed with this step?

댓글 수: 3

Rik
Rik 2021년 4월 23일
Why do you want to use str2num? You should be using str2double or textscan instead.
What data type is app.SaveButton?
What about this? I made some edits:
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
D = str2double(app.UITable.Data); % Assigning a variable to the table
fileid = fopen ('C:\**\**\**\**\***\**\****.txt','w');
fprintf(fileid, '%6.2f' , D);
I am using str2double on my table of data and my text file output reads:
NaN
What should I to do in order to write the data from my table to the text file?
Rik
Rik 2021년 4월 28일
Is app.UITable.Data a numeric data type that is supported by str2double?

댓글을 달려면 로그인하십시오.

 채택된 답변

I
I 2021년 4월 28일

0 개 추천

It seems I figured out the issue just based on your question alone.
I tried to just save the data straight to the text file and got an error returned
D = (app.UITable.Data(:,:)); % Assigning a variable to the table
Error using fprintf
Unable to convert 'table' value to 'double'.
Thist prompted me to "assume" that using an additional function was necessary. It's not. I don't completely know how to interact with app.UITable.Data, but I can extract the data entries. One of those entries is Thrust.
D = (app.t.Thrust(:,:));
The above resulted in:
0.00
1000.00
Problem solved.

추가 답변 (0개)

카테고리

제품

릴리스

R2020b

질문:

I
I
2021년 4월 23일

답변:

I
I
2021년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by