Do not understand why my code isn't working!
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Francisco Araujo
le 12 Oct 2014
Réponse apportée : Image Analyst
le 12 Oct 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 commentaires
Réponse acceptée
Roger Stafford
le 12 Oct 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 commentaires
Plus de réponses (1)
Image Analyst
le 12 Oct 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 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!