why readtable create field "D" in the struct "D1"
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
function D1=TEST()
D=readtable('test.txt','delimiter',',');
save canc.tset D
D1=load('canc.tset',"-mat")
end
i access it using
D1.D...
it's possibile to avoid "D" field?

1 件のコメント
"why readtable create field "D" in the struct "D1""
It doesn't. READTABLE has nothing to do with the scalar structure returned by LOAD.
採用された回答
If there is only one variable in the MAT file (regardless of its extension) and you do not know/care what its name is:
C = struct2cell(load(..));
assert(isscalar(C),'Only one array can be LOADed')
T = C{1}
If the variable name is known in advance, e.g. "D"
S = load(..)
T = S.D
12 件のコメント
Honestly, I didn't quite understand what you wrote above :D
but if you tell me to do
S = load(..)
T =S.D
ok I will Thank you!
shamal
2023 年 6 月 16 日
I tried to save the new table but I find confusing indications in the community and in matlab Could you tell me how to do it? Thank you
Stephen23
2023 年 6 月 17 日
writetable(T,'mytable.csv')
shamal
2023 年 6 月 17 日
編集済み: Walter Roberson
2023 年 6 月 17 日
I summarize: I have this table in .mat format

I call it with the command:
[file2,path] = uigetfile({'*.ttslist2'}, 'Select a file');
and i import it using :
T1=importdata(strcat(path,file2));
now T1 is a cell format
In app designer i call this function and
app.UITable.Data=(T1);
- now i've a table
- later I change some table values
Now that I have the new table I want to save it in the original .mat format so I can't use saving in .txt)
Stephen23
2023 年 6 月 17 日
"Now that I have the new table I want to save it in the original .mat format so I can't use saving in .txt)"
Then select an appropriate function for that file format (read the link that I gave you).
Avoid IMPORTDATA.
Ok i used matfile to do it.
but now i want to save new table
i used cell2table and writetable but i get this file:

but i want this type :

They look the same to me: both look like CSV files (interpreted by some application which you do not specify). But instead of comparing screenshots, you need to compare the actual text data (which is what CSV files are).
If you want more help, upload the actual CSV files and original MAT file by clicking the paperclip button.
shamal
2023 年 6 月 17 日
編集済み: Walter Roberson
2023 年 6 月 17 日
the first file (Test2.mat) is original named : TEST.ttslist2 but i change extension in .mat otherwise it couldn't sending it
the second file is created by me by coding:
[file2,path] = uigetfile({'*.ttslist2'}, 'Select a file');
if file2
%T1=importdata(strcat(path,file2));
vv=matfile(strcat(path,file2));
T1=vv.StratList;
T = cell2table(T1 )
writetable(T,"prova,txt");
Stephen23
2023 年 6 月 17 日
"Now that I have the new table I want to save it in the original .mat format "
Then you should be using SAVE, not WRITETABLE for exporting the data.
Avoid IMPORTDATA, use LOAD instead.
shamal
2023 年 6 月 17 日
編集済み: Walter Roberson
2023 年 6 月 17 日
i try it but i get error
save('prova.txt',T)
Error using save
Argument must be a text scalar.
(my data is number..string.. )
Stephen23
2023 年 6 月 17 日
save('prova.txt','T')
SAVE is an exception: it requires the name/s of the variable/s that you want to save, not the variables themselves. That is explained and shown in the SAVE documentation. You should look at the documentation of every function that you use.
shamal
2023 年 6 月 17 日
thank you.. I appreciate the effort you took in answering me
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
