gpt4 book ai didi

Matlab函数返回值

转载 作者:太空宇宙 更新时间:2023-11-03 19:50:03 25 4
gpt4 key购买 nike

我有一个程序有功能和问题,返回值,它有太多的输出。

例如:y = text the answer comes up

Error in text (line 2)

if nargin == 0

Output argument "array" (and maybe others) not assigned during call to "
C:\Users\name\Documents\MATLAB\text.m>text".

程序 text.m 读取一个 txt 文件,其中包含几个名称和数字,例如

例子:

约翰·道拉斯 15986

菲利普杜赫 357852

等等。程序将它们转换为 15986 Doughlas John 等。

function array = text(~) 
if nargin == 0
dirr = '.';
end
answer = dir(dirr);
k=1;
while k <= length(answer)
if answer(k).isdir
answer(k)=[];
else
filename{k}=answer(k).name;
k=k+1;
end
end
chose=menu( 'choose file',filename);
namn = char(filename(chose));
fid = fopen(namn, 'r');
R = textscan(fid,'%s %s %s');
x=-1;
k=0;
while x <= 24
x = k + 1;
All = [R{3}{x},' ',R{1}{x},' ',R{2}{x}];
disp(All)
k = k + 1;
end
fclose(fid);

有没有办法不用从头开始就解决这个问题?

感谢所有的回答!

最佳答案

您在定义中指定了函数输出参数,但您没有在函数体中为其分配任何内容。

例如,在

function y = student(j)                                

你的输出是y。所以你必须给 y 赋值。

阅读更多关于 functions 的信息在 MATLAB 中。

关于Matlab函数返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15954838/

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