matlab - 将文本插入文件的功能。 Matlab的

标签 matlab text compiler-errors

我目前正在从事这项工作

function[check] = store( filename, persons )

fid = fopen(filename,'w');

if exist('fid')
    check = true;
else
    check = false;
end


for i=1:length(persons)

    sprintf(fid, '%s\n',serialize_person(persons(i)));
end
end

Serialize_person返回<1x(length)char>。
如果要使用store函数创建一个名为“文件名”的.txt文件,并将serialize_person(persons(i))放在该文本文件的第i行上,我想要什么。

但是,即使serialize_person本身运行正常,当我尝试运行存储功能时,也会收到错误消息
Attempt to reference field of non-structure array.

Error in serialize_person (line 3)
out=sprintf ( '<%s>#%s#<%i>\n' , person.name, serialize_date( person.date_of_birth),
person.phone );

Error in store (line 14)
sprintf(fid, '%s\n',serialize_person(persons(i)));

关于什么可能有问题的任何有根据的猜测?

最佳答案

function[check] = store( filename, persons )

fid = fopen(filename,'w');

if exist('fid')
    check = true;
else
    check = false;
end


for i=1:length(persons)

    sprintf(fid, '%s\n',serialize_person(persons{i}));
end
end

这是引起人们关注的简单错误之一。人是结构的单元,可以将每个夹点放入serialize_person中。因此,解决问题的方法只是在for循环中将(i)更改为{i}。

关于matlab - 将文本插入文件的功能。 Matlab的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136050/

相关文章:

MATLAB : Plot multiple lines in a single graph with different colors and Legend them.

matlab - 在频域中改变信号的相位

c++ - 我的粒子群优化代码在 C++ 和 MATLAB 中生成了不同的答案

image - MATLAB:以原始大小显示图像

c - 使用堆栈以相反顺序打印字符串时出错

asp.net-mvc - Razor 编译器警告/错误 - ASP.NET MVC 4

java - 如何让我的文本每行不打印一个字符?

html - 表格下方的文字

algorithm - 文本搜索算法

javac 错误消息不显示整个文件路径