How can I make a function from this few lines of codes?
1 view (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Voss
on 17 Feb 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
0 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!