How can I make a function from this few lines of codes?

1 visualización (últimos 30 días)
Ashfaq Ahmed
Ashfaq Ahmed el 17 de Feb. de 2023
Respondida: Voss el 17 de Feb. de 2023
Hi all, can anyone please tell me how can I make function of this calculation so that I can perform the same operation for any given range of A?
clear all; close all; clc;
A = -40:2:40;
B = A(find(A>0))./max(A);
C = -A(find(A<=0))./min(A);
D = [C,B];
figure(1),
subplot(2,1,1)
plot(1:numel(A),A);
subplot(2,1,2)
plot(1:numel(D),D)

Respuestas (1)

Voss
Voss el 17 de Feb. de 2023
% calling the function defined below
filter_and_plot(-40:2:40)
% defining the function
function filter_and_plot(A)
B = A(find(A>0))./max(A);
C = -A(find(A<=0))./min(A);
D = [C,B];
figure()%(1),
subplot(2,1,1)
plot(1:numel(A),A);
subplot(2,1,2)
plot(1:numel(D),D)
end

Community Treasure Hunt

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

Start Hunting!

Translated by