function h = plottenbar(x) if length(x) ~= 10; error('Input argument need to be of size x'); end % Plots the ten bar truss with cross areas given in abs(x). % If a component of x is negative its color is red otherwise blue. % The numbering of the bars corresponds to the figure: % % 1 6 % 1-----2-----3 % \ /|\ /| % 2\3/ |7\8/ | % X 5| X | 10 % / \ | / \ | % / \|/ \| % 4-----5-----6 % 4 9 % y = abs(x); nodeCoordinates = [ 0 2 %node 1 1 2 %node 2 2 2 0 1 1 1 2 1]; % node 6 startAndStopNode = [ 1 2 %bar 1 1 5 %bar 2 2 4 4 5 2 5 2 3 2 6 5 3 5 6 3 6]; %bar 10 h = figure; axis([0 2.5 0 2.5]); axis('square'); set(gca, 'Visible','off'); maxSize = max(y); for i = 1:length(y) if y(i) > 0.01*maxSize hl = line([nodeCoordinates(startAndStopNode(i,1),1) nodeCoordinates(startAndStopNode(i,2),1)], ... [nodeCoordinates(startAndStopNode(i,1),2) nodeCoordinates(startAndStopNode(i,2),2)]); set(hl,'LineWidth', 10*y(i)/maxSize); if x(i) < 0 set(hl,'Color', 'red'); else set(hl,'Color', 'blue'); end end end end