Building array with custom function
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am facing a problem with building an array using a custom function.
I would like to transfer a task from the main script file to the function file. I have such a piece of script:
StageMain=0;
TStart=10;
TEnd=500;
TStep=0.001;
Tmag=1;
.
.
.
DataInput = ones(length(StageMain),8);
Tarray = ones(1,length(StageMain));
.
.
.
T=TStart;
while T<TEnd
T=T+TStart*StageMain;
StageMain=StageMain+TMag;
DataInput(StageMain,1) = double(T);
Tarray(1, StageMain) = double(T);
end
its job is to build (actually update) two arrays DataInput and Tarray. Now I am trying to put this in function file which also will give me two updated arrays.
function [DataInput, Tarray] = arraybuilder(TStart, TEnd, TStep, TMag, StageMain)
T=TStart;
while T<TEnd
T=T+TStep*StageMain;
StageMain=StageMain+TMag;
DataInput(StageMain,1) = double(T);
Tarray(1, StageMain) = double(T);
end
however, it only builds one vertical array that has double-length and the first part is filled with 0 and the second one with correct answers for DataInput
Thank you for any ideas.
5 个评论
采纳的回答
Roger J
2020-7-20
If you don't assign the return values from a function call, then only the first is assigned to the default
ans
variable.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!