How to declare multiple output arguments ?
显示 更早的评论
I have declared in one .m file all the following output arguments for my function preprocessing_data. The input arguments are the number of the samples gathered for each movement that I am investigating.
Here is what it looks like:
function [Ext, Flx, Stft_ext, Stft_flx,Rms_ext, Rms_flx,...
Smoothed_ext, Smoothed_flx, Haar_ext, Bior13_ext, Db8_ext,...
Bior22_ext, Sym4_ext, Coif3_ext,Sym8_ext, Coif4_ext,...
Haar_flx, Bior13_flx, Db8_flx, Bior22_flx, Sym4_flx,...
Coif3_flx, Sym8_flx, Coif4_flx, Amor_ext, Bump_ext, Morse_ext] = preprocessing_data(Ext_dim,Flx_dim)
It seems to me that this is not the right way to declare output argument and there is a more elegant way of doing this. Another problem with that is that I do not get the output arguments is spite of having them declared.
Could someone guide me how to fix this ?
Thanks in advance!
7 个评论
That is the correct way of defining multiple output arguments, but really more then seven or eight input/output positional arguments is not a very good practice...
"I do not get the output arguments is spite of having them declared"
And that is exactly why.
You would be much better off putting all of those values into one structure, and simply passing that. Using one structure would be simple, neat, efficient, robust, clear, and easy to understand.
Ioannis Agalliadis
2017-7-4
Adam
2017-7-4
No single function should ever require that many outputs. You don't need to go quite to the extreme of a function to 'Do one thing and do it well', but functions should be as focussed as possible and use many functions to achieve a more complex outcome.
Your function takes 27 outputs (yes, I don't know why I bothered to count them!) which is way more than any function should ever need. You should never be wanting to call one function and ask it to do 27 things!
Ioannis Agalliadis
2017-7-4
编辑:Ioannis Agalliadis
2017-7-4
Ioannis Agalliadis
2017-7-4
Adam
2017-7-4
"I tried to invoke by typing output.name(2)"
That is what he is talking about - it is the key detail and you never mentioned it previously.
You created a struct array with 1 field called 'name' in each element of the struct.
This needs to be accessed as:
output(2).name;
as you would see from examining the struct you created.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!