Iterating array of chars and saving to table or cell

8 ビュー (過去 30 日間)
M
M 2021 年 6 月 5 日
コメント済み: J. Alex Lee 2021 年 6 月 5 日
I want to make a loop that would allow me to iterate using this function
GeneontObj(temp(i,1)).terms.definition;
For example if I'll do
T = GeneontObj(temp(1,1)).terms.definition
I will receive
T = ""A multimeric enzyme complex, usually a dimer or an octamer,
that catalyzes the conversion of 2-phospho-D-glycerate to phosphoenolpyruvate and water."
[GOC:jl, ISBN:0198506732]"
My iterator has about 1500 records, and I would like to save an array like T above to a table, each row for each iteration.
With other data than char/strings I'd do something like:
result = zeros(length(temp), 1)
for i = 1:length(temp)
result(i) = GeneontObj(temp(i,1)).terms.definition;
end
but because it is char i have an error:
Unable to perform assignment because the left and right sides have a different number of elements.
It would be perfect, if there is a way to store this data in table, but cell array will also work.

採用された回答

J. Alex Lee
J. Alex Lee 2021 年 6 月 5 日
編集済み: J. Alex Lee 2021 年 6 月 5 日
Try this, if your function actually returns strings as your output suggests (rather than a char array)
result = strings(length(temp), 1)
for i = 1:length(temp)
result(i) = GeneontObj(temp(i,1)).terms.definition;
end
But this is not a "table" in the sense of a matlab table data type...
  2 件のコメント
M
M 2021 年 6 月 5 日
Thank you! After this, i changed result into cell array, and then cell array to a table and everything works perfectly :)
a = cellstr(result);
studyResult = cell2table(a);
J. Alex Lee
J. Alex Lee 2021 年 6 月 5 日
Glad it helps. You shouldn't have to go through a cell array, you should be able to just do
studyResult = array2table(result)

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by