Appdesigner Importing Numerical Data via Notepad

1 回表示 (過去 30 日間)
I
I 2022 年 3 月 4 日
移動済み: Rik 2023 年 6 月 23 日
I thought what I was trying to do was fairly simple, but I am still having issues. I will first explain what I am trying to do, and then I will show my current code. Followed by errors
All I wanted to do is import a textfile that has 1 row of 10 numbers.
Here is my code:
% Button pushed function: InputDataButton
function InputDataButtonPushed(app, event)
[filename, path] = uigetfile('*.txt');
figure(app.UIFigure);
T = readtable(filename);
ct = T(:, 1);
cr = T(:, 2);
angle_sweep_chord = T(:,3);
angle_cant = T(:,4);
thick_fin = T(:,5);
span = T(:,6);
fin_location = T(:,7);
fin_num = T(:,8);
mass_fin = T(:,9);
stage_fin = T(:,10);
app.ctEditField.Value = ct;
app.crEditField.Value = cr;
app.angle_sweep_chordEditField.Value = angle_sweep_chord;
app.angle_cantEditField.Value = angle_cant;
app.thick_finEditField.Value = thick_fin;
app.spanEditField.Value = span;
app.fin_locationEditField.Value = fin_location;
app.fin_numnEditField.Value = fin_num;
app.mass_finEditField.Value = mass_fin;
app.stage_finEditField.Value = stage_fin;
I am opening the file, setting T equal to the content of that file, and then setting each of my variables equal to a part of T.
For this line
cr = T(:, 2);
Variable index exceeds table dimensions.
I also tried
cr = T.Var2(:, 2);
Dot indexing is not supported for variables of this type.
I cannot use str2double or table2array.
What can I try?
  3 件のコメント
Anna H.
Anna H. 2022 年 3 月 4 日
It looks like there is something wrong with readtable. Can you examine the value of T after:
T = readtable(filename);
How are the numbers separated from each other?
I
I 2022 年 3 月 5 日
You're right. There is is something wrong with this. Here are the contents of the textfile:
0.09 0.45 45 0 0.006 0.242 4.67 4 0.89925 1

サインインしてコメントする。

採用された回答

Kojiro Saito
Kojiro Saito 2022 年 3 月 6 日
After putting a breakpoint, it turns out that T is empty table.
readtable tries to read the txt file with comma delimeter.
So, you just need to add options 'Delimeter', 'space' in readtable.
[filename, path] = uigetfile('*.txt');
T = readtable(filename, 'Delimiter', 'space');
ct = T(:, 1);
cr = T(:, 2);
  1 件のコメント
I
I 2022 年 3 月 7 日
移動済み: Rik 2023 年 6 月 23 日
I still had an error with the bottom part of the code that I fixed with table2array. The numbers are reading in now, thanks for your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by