Is it possible to save the output of a command as a variable?

9 ビュー (過去 30 日間)
Nadeau Hahne
Nadeau Hahne 2022 年 1 月 13 日
コメント済み: Nadeau Hahne 2022 年 1 月 13 日
If have data in PDF format, is it possible to use the file name as the variable name for the table created from the extracted data? I need to extract data from many files (Test1-100) so I am trying to automate part of the process so I can aggregate the information.
file = 'Test1.pdf';
[pathstr, TestNumber, ext] = fileparts(file);
str = extractFileText(file);
numbers = extractBetween(str, 'Start', 'Stop')
x = str2num(extractBetween(numbers, '0', '10'));
y = str2num(extractBetween(numbers, '11,' '20'));
table = array2table([x;y], 'VariableNames', {'Area 1', 'Area2'})
What syntax do I use to make "Test1" the variable name of the table??
  2 件のコメント
Stephen23
Stephen23 2022 年 1 月 13 日
Do NOT use ASSIGNIN or anything similar, unless you want to force yourself into writing slow, complex, inefficient code:
Unfortunately beginners learn bad code practices like this and then wonder why their code is incredibly inefficient and hard to work with. The simple and very efficient MATLAB approach is to use indexing into one array (e.g. a cell array).
Nadeau Hahne
Nadeau Hahne 2022 年 1 月 13 日
Thank you for your caution Stephen

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 1 月 13 日
編集済み: Fangjun Jiang 2022 年 1 月 13 日
VarName='Test1';
assignin('base',VarName,table)
  2 件のコメント
Nadeau Hahne
Nadeau Hahne 2022 年 1 月 13 日
works Perfectly!! Was trying to figure this out for a while Thank you!
Stephen23
Stephen23 2022 年 1 月 13 日
"works Perfectly" at making it slow and complex to process your data.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by