Turn code into function

1 visualizzazione (ultimi 30 giorni)
Paula Barreiro
Paula Barreiro il 14 Set 2022
Modificato: Jan il 14 Set 2022
FP= {'Please enter three frequencies [f1 f2 f3]:'};
prompt_title = 'Frequency Data?';
dims = [1 1000];
default = {'1 1 1'};
FP_index = inputdlg(FP, prompt_title, dims, default);
FP_MATRIX = cell2mat(FP_index)
AMP= {'Please enter three amplitudes [a1 a2 a3]:'};
prompt_title1 = 'Amplitude Data?';
dims = [1 1000];
default = {'1 1 1'};
AMP_index = inputdlg(AMP, prompt_title1, dims, default);
AMP_MATRIX = cell2mat(AMP_index)
T= linspace(1,3,1000)
Sin1= AMP_MATRIX(1)*sin(2*pi*FP_MATRIX(1)*T)
Sin2= AMP_MATRIX(2)*sin(2*pi*FP_MATRIX(2)*T)
Sin3 = AMP_MATRIX(3)*sin(2*pi*FP_MATRIX(3)*T)
plot(T,Sin1,'-g',T,Sin2,'-b',T,Sin3,'-k')
hold on;
Sin= Sin1 + Sin2 +Sin3
plot(T,Sin,'-r','LineWidth',2);
xlabel('Time');
ylabel('Signals')
legend('S_1','S_2','S_3','Output signal');
title('Plots of three signals and sum')
hold off
My code is above I am trying to turn this whole thing into a function using one line of code.

Risposte (1)

Jan
Jan il 14 Set 2022
Modificato: Jan il 14 Set 2022
Instert one line on top:
function ANameOfYourchoice
and save the file as "ANameOfYourchoice.m".

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by