Ex 9.6
Dynamiskt ändra färg på linje
t = -2:0.1:2; x1 = cos(t/pi); x2 = 2*sin(t/(2*pi)); %fighndl = figure(1); %axishndl = axes; line1 = plot(t,x1); hold on; line2 = plot(t,x2); hold off; textobj1 = title('Ex 9.6'); textobj2 = legend('cos(t/\pi)','2sin(t/(2\pi))'); % Check properties of line1 disp('Egenskaper hos line1:'); get(line1) set(line1,'LineWidth', 4); set(line2,'LineWidth', 4); % Check what options available for LineStyle disp('Parametrar tillgängliga för LineStyle:'); set(line2,'LineStyle'); set(line2,'LineStyle','--'); k = waitforbuttonpress; % k=0 för musklick, k=1 för tangentbord while k == 0 % vilket objekt klickades? handle = gco; typ = get(handle,'Type'); disp(['Klickade på objekt av typ: ' typ]); if strcmp(typ,'line'); f = [rand rand rand]; disp(['Ändrar färg till (rgb): ' num2str(f,2)]); set(handle, 'Color', f); end k = waitforbuttonpress; end
Egenskaper hos line1: Color: [0 0 1] EraseMode: 'normal' LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerEdgeColor: 'auto' MarkerFaceColor: 'none' XData: [1x41 double] YData: [1x41 double] ZData: [1x0 double] BeingDeleted: 'off' ButtonDownFcn: [] Children: [0x1 double] Clipping: 'on' CreateFcn: [] DeleteFcn: [] BusyAction: 'queue' HandleVisibility: 'on' HitTest: 'on' Interruptible: 'on' Selected: 'off' SelectionHighlight: 'on' Tag: '' Type: 'line' UIContextMenu: [] UserData: [] Visible: 'on' Parent: 413.0068 DisplayName: 'cos(t/\pi)' XDataMode: 'manual' XDataSource: '' YDataSource: '' ZDataSource: '' Parametrar tillgängliga för LineStyle: [ {-} | -- | : | -. | none ] Klickade på objekt av typ: line Ändrar färg till (rgb): 0.45 0.43 0.83