assign variable name to Function Output Variables
显示 更早的评论
Hi All
when using a Function it is possible to assign a variable name to the input
e.g
wave = Uph
[.........] = waveform(wave)
Is it possible to use the same variable in the output definition
[wave_rms]=waveform(wave)
so the output variable stored in the workspace is Uph_rms and not wave_rms?
Thanks
Adrian
回答(1 个)
M
2019-11-8
0 个投票
Why don't you just change [wave_rms]=waveform(wave) into [Uph_rms]=waveform(wave) ?
5 个评论
Guillaume
2019-11-8
And note that the brackets are not necessary
wave_rms = waveform(wave);
uph_rms = waveform(uph);
The variable to which you assign the output of a function to call does not have to match the name that is defined in the function signature. This is exactly how it works for built-in functions, it's no different for the function you write.
Guillaume
2019-11-8
Adrian's comment originally posted as an answer moved here:
I have 20 waveforms to process and i dont want to hard code each function
e.g
wave=Uph
[wave_rms]=waveform(wave)
then
wave = Vph
[wave_rms]=waveform(wave)
my function has 15 output definitions so would take a long time to hard code.
Guillaume
2019-11-8
These 20 waveforms are they 20 different variables? or are they more sensibly stored in a container of some sort (cell array, matrix, table,...)?
Adrian
2019-11-8
Guillaume
2019-11-8
They are 20 different variables
That's where you went wrong and what we have to fix. How were these 20 different variables created in the first place.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!