필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by