gpt4 book ai didi

string - 如何从matlab中的表格单元格中提取字符串

转载 作者:行者123 更新时间:2023-12-05 04:07:33 58 4
gpt4 key购买 nike

我在 Matlab 中导入了一个 csv 文件data_tr

1, abc
2, def
...

现在打算像这样在我的代码中使用字符串

save_location = strcat('trial\tr_',data_tr(i,2),'.png');

这导致了以下错误:

Inputs must be character vectors, cell arrays of character vectors, or string arrays.

变量 data_tr(i,2) 被认为是 1x1 表而不是字符串。

在看到一些答案(this 一个)后,我也尝试了这个:

da = data_tr(i,2);
h = [da{:}];
save_location = strcat('trial\tr_',h,'.png');

但这显示了一个下标错误:

Error using main (line 14 (ie line h=[da{:}];) )

You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or moresubscripts). Use a row subscript and a variable subscript.

谁能帮我从 csv 文件中提取字符串。

最佳答案

要么使用大括号访问表格元素

data_tr{i,2} % Get the element of a table rather than data_tr(I,2)

或者将其转换为单元格,因为 strcat 可以接受单元格输入

data_tr_cell = table2cell(data_tr);
data_tr_cell(i, 2);

关于string - 如何从matlab中的表格单元格中提取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48633462/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com