Do not understand why my code isn't working!
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Francisco Araujo
am 12 Okt. 2014
Beantwortet: Image Analyst
am 12 Okt. 2014
it should be simple, but nothing show in the figure and nothing is reported by the debugger.
x1=linspace(0,0.1,0.49);
x2=linspace(0.51,0.1,1);
y1=1./(2*x1-1);
y2=1./(2*x2-1);
plot(x1,y1), plot(x2,y2), grid
0 Kommentare
Akzeptierte Antwort
Roger Stafford
am 12 Okt. 2014
The third argument in 'linspace' is interpreted as the number of desired points, so you will get at most one point in each one. It is not the same as the colon operator. See
http://www.mathworks.com/help/matlab/ref/linspace.html
0 Kommentare
Weitere Antworten (1)
Image Analyst
am 12 Okt. 2014
You're mixing two ways of specifying a range of variables into one single way that does not work. Here, check out my code to see the two ways. Just pick one of them:
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.
fontSize = 20;
% Two ways of specifying x. Pick one:
% Method 1:
x1 = 0 : 0.1 : 0.49;
x2 = 0.51 : 0.1 : 1;
% Method 2:
x1 = linspace(0, 0.1, 15);
x2 = linspace(0.51, 0.1, 300);
y1=1./(2*x1-1);
y2=1./(2*x2-1);
plot(x1,y1, 'bo-', 'LineWidth', 2)
hold on;
plot(x2,y2, 'r*-', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Y1 and Y2 vs. X', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);

0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!