我试图遍历MATLAB中的字符串列表。问题在于,在“for”循环内,我的迭代器被视为“单元”而不是字符串。
for str = {'aaa','bbb'}
fprintf('%s\n',str);
end
??? Error using ==> fprintf
Function is not defined for 'cell' inputs.
解决此问题的正确/优雅方法是什么?
最佳答案
您应该通过str{1}
调用单元格的内容,以使其正确:
for str = {'aaa','bbb'}
fprintf('%s\n',str{1});
end
这是关于打印单元格数组内容的more sophisticated example。
关于string - 遍历MATLAB中的字符串列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10687611/