フィルターのクリア

What is the error of my plot?

2 ビュー (過去 30 日間)
Gabriel Oliviero
Gabriel Oliviero 2016 年 1 月 24 日
コメント済み: Image Analyst 2016 年 1 月 24 日
if true
% code
endm5=1.78
c6=0.00036
c7=0.02
c8=0.00004
c9=0.1
k6=167.00
k8=623.00
F = 80
for w= 20:100:1000
x5(end+1) = F/(sqrt(((k6+k8)-(m5*w))^2+((c6+c7+c8+c9)*w)^2))
end
plot (w,x5)
I can't see why the plot is wrong. Could please somebody help?

採用された回答

Image Analyst
Image Analyst 2016 年 1 月 24 日
You're plotting x5 vs the LAST value of w (a scalar that you used as the loop index), not the whole array. Try reassigning w to the whole array before plotting:
w = 20 : 100 : 1000;
plot(w, x5)
  3 件のコメント
Gabriel Oliviero
Gabriel Oliviero 2016 年 1 月 24 日
I fixed that declaring x5 = [].
Thank you for your help!!!
Image Analyst
Image Analyst 2016 年 1 月 24 日
You might like this code better:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
m5=1.78
c6=0.00036
c7=0.02
c8=0.00004
c9=0.1
k6=167.00
k8=623.00
F = 80
w = 0 : 10 : 1000;
x5 = zeros(size(w));
for index = 1 : length(w)
x5(index) = F/(sqrt(((k6+k8)-(m5*w(index)))^2 + ((c6+c7+c8+c9)*w(index))^2))
end
plot (w,x5, 'b*-', 'LineWidth', 2, 'MarkerSize', 12)
grid on;
xlabel('w', 'FontSize', fontSize);
ylabel('x5', 'FontSize', fontSize);
title('x5 vs. w', 'FontSize', fontSize);
ylim([0, 1.5]);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by Gabriel', 'NumberTitle', 'Off')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by