How can I make a function from this few lines of codes?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Voss
2023-2-17
% 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!