i have a function that draws a random shape but i want to be able to call it 10 times to the same plot so 10 different shapes are drawn around the same point and on the same figure how do I do this?
function plotfunc() figure(); prompt = {'Enter Number of vertices:',} numberOfVertices = str2num(cell2mat(inputdlg(prompt, 'enter a number', 5))) %numberOfVertices = 7; % Fixed at 7 for this demo. coordinates = rand(numberOfVertices, 2); coordinates(1,:) = [0, 0]; % Force first coord to 0,0 coordinates(end+1,:) = [0, 0]; % Force last coord to 0,0 hold on; plot(coordinates(:,1), coordinates(:,2)); hold on plot(coordinates(:,1), -coordinates(:,2)); hold on plot(-coordinates(:,1), coordinates(:,2)); hold on plot(-coordinates(:,1), -coordinates(:,2)); grid off; randomColor = rand(1,3); patch(coordinates(:,1), coordinates(:,2), randomColor); % Can use fill() also. patch(coordinates(:,1), -coordinates(:,2), randomColor); % Can use fill() also. patch(-coordinates(:,1), coordinates(:,2), randomColor); % Can use fill() also. patch(-coordinates(:,1), -coordinates(:,2), randomColor); % Can use fill() also. axis off; end
Just use a loop, after the first line (after figure()), use
for i=1:10 ...%Put code here end
Make sure to add the end. You might want to move the position where the for loop starts till after the numberOfVertices line so the user doesn't put a new number of vertices every time.
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.