How to access a table using the string from within a cell as part of the dot notation index

5 ビュー (過去 30 日間)
Hi, I have thousands of textiles that over the years have been formatted differently, for example velocity data may be in column2 in one file but in column 5 in another. I have some code that finds which column velocity is in, and then I want my script to access that column of the table, but I'm falling over with the last part where I use dot notation consisting of the table name and the columnID which I derived from the code, any ideas?
close all
clear all
clc
A={'Exp ID','drop1: Average Radius',...
'drop1 volume (pl)','trajectory','velocity (m/s)',...
'average velocity (m/s)','Comments', 'Time'};
possibleVolStr={'Volume_pl','volume_pl','drop1 volume (pl)',...
'drop1 Volume (pl)','Volume'}
VolOuty = ismember(A,possibleVolStr)
[~,VolColID] = find(VolOuty)
VolCol_header={A(VolOuty)}
VolCol_header_title=['A' num2str(VolColID)]
dataNew=cell2table(A)
Z={VolCol_header_title}
Z=convertCharsToStrings(Z)
vol=dataNew.Z
%VolColID tells us which column is the volume
The error is: >> Error using column_moving_05 (line 45) Unrecognized variable name 'Z'.

採用された回答

Stephen23
Stephen23 2018 年 6 月 8 日
編集済み: Stephen23 2018 年 6 月 8 日
  2 件のコメント
Stephen Devlin
Stephen Devlin 2018 年 6 月 8 日
I get this when I run it steve
Error using untitled434 (line 26) Table variable names must be character vectors.
I have figured out I can do it with vol=datanew(:,VolColID) but I was puzzled as to why I couldn't do it with dot notation which is what I usually use for table indexing
Stephen23
Stephen23 2018 年 6 月 8 日
編集済み: Stephen23 2018 年 6 月 8 日
Simplify your code: get rid of the convertCharsToStrings and find.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by