Do not understand why my code isn't working!

8 visualizaciones (últimos 30 días)
Francisco Araujo
Francisco Araujo el 12 de Oct. de 2014
Respondida: Image Analyst el 12 de Oct. de 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

Respuesta aceptada

Roger Stafford
Roger Stafford el 12 de Oct. de 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

Más respuestas (1)

Image Analyst
Image Analyst el 12 de Oct. de 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]);

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by