if true % code
end
MATLAB: How to plot the figure
plotting
Related Solutions
Try this:
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;x1=0;x2=10;y1=0;y2=10;wholeHousex = [x1, x2, x2, x1, x1];wholeHousey = [y1, y1, y2, y2, y1];plot(wholeHousex, wholeHousey, 'b-', 'LineWidth', 3);xlabel('Length')ylabel('Width')hold on;text(3,5,'total house W-L')% Room 1
x1=0;y1=0;x2=2;y2=3;room1x = [x1, x2, x2, x1,x1];room1y = [y1, y1, y2, y2,y1];plot(room1x, room1y, 'r', 'LineWidth', 3);hold on;% Room 2
x1=2;y1=0;x2=5;y2=3;room2x = [x1, x2, x2, x1,x1];room2y = [y1, y1, y2, y2,y1];plot(room2x, room2y, 'g', 'LineWidth', 3);hold on;% Room 3
x1=5;y1=0;x2=10;y2=3;room3x = [x1, x2, x2, x1,x1];room3y = [y1, y1, y2, y2,y1];plot(room3x, room3y, 'k', 'LineWidth', 3);hold on;% Room 4
x1=0;y1=6;x2=3;y2=10;room4x = [x1, x2, x2, x1, x1];room4y = [y1, y1, y2, y2, y1];% Ask the user to click two lines. You can use improfile() or imdistline() of you have the Image Processing Toolbox.
uiwait(helpdlg('Click on two points.'))[xUser, yUser] = ginput(2) %this gives me the 2 points
plot(xUser, yUser, 'ro--', 'LineWidth', 2);% Make flag array to find out if the point is in there.
% One row for every room. We don't need to check if it's in the entire house since we assume it will be.
inRoom = false(3, 2); % Column 1 for point 1, column 2 for point 2.
% See if points 1 and 2 are in room 1.
if inpolygon(xUser(1), yUser(1), room1x, room1y) % The first point is in the whole house
inRoom(1, 1) = true;endif inpolygon(xUser(2), yUser(2), room1x, room1y) % The first point is in the whole house inRoom(1, 2) = true;end% See if points 1 and 2 are in room 2.
if inpolygon(xUser(1), yUser(1), room2x, room2y) % The first point is in room 2.
inRoom(2, 1) = true;endif inpolygon(xUser(2), yUser(2), room2x, room2y) % The second point is in room 2.
inRoom(2, 2) = true;end% See if points 1 and 2 are in room 3.
if inpolygon(xUser(1), yUser(1), room3x, room3y) % The first point is in room 3.
inRoom(3, 1) = true;endif inpolygon(xUser(2), yUser(2), room3x, room3y) % The second point is in room 3.
inRoom(3, 2) = true;end% Display results:
inRoom% Find out if both points are in the same room
roomCount = sum(inRoom, 2)if any(roomCount == 2) % Then both points are in the same room
message = 'Both points are in the same room'; uiwait(helpdlg(message)); return;end% Find out where point 1 is by inspecting column 1 for a 1.
point1room = find(inRoom(:, 1))% Find out where point 2 is by inspecting column 2 for a 1.
point2room = find(inRoom(:, 2))if isempty(point1room) % In whole house but not in any room. Just say it's room 0.
point1room = 0;endif isempty(point2room) % In whole house but not in any room.
point2room = 0;endmessage = sprintf('Point 1 is in room %d, and Point 2 is in room %d', ... point1room, point2room);uiwait(helpdlg(message));
Try this:
w = 1;a = 1;r = linspace(0, 3, 500);vth = w .* r;% Get indexes where r is more than 1.
mask = r > 1; % Do second (right) part of the equation.
vth(mask) = (w*a^2) ./ r(mask);subplot(1, 2, 1);plot(r, vth)axis equalxlim([0, 3]);ylim([0, 2]);% Plot dashed vertical line
hold on;line([a, a], ylim, 'LineStyle', '--', 'Color', 'k', 'LineWidth', 2);xlabel('r', 'FontSize', 20);ylabel('u', 'FontSize', 20);subplot(1, 2, 2);plot([0, a], [2, 2], 'k-', 'LineWidth', 2);xlim([0, 3]);ylim([0, 3]);% grid on;
xlabel('r', 'FontSize', 20);ylabel('w', 'FontSize', 20);% Plot dashed vertical linehold on;line([a, a], ylim, 'LineStyle', '--', 'Color', 'k', 'LineWidth', 2);
Best Answer