Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% data generation
- rng(5000);
- N_detector = 4;
- N_timePoints = 3;
- velocity = 30 + randi(40, N_detector, N_timePoints);
- distance_detectors = randi(20, N_detector-1, 1);
- detector_location = cumsum([0; distance_detectors]);
- %% first graph - velocity v.s. time
- fig = figure;
- col = {'b', 'r', 'g', 'c'};
- shape = {'d', 's', 'o', 'v'};
- legend_num = zeros(N_detector, 1);
- for i = 1:N_detector
- for j = 1:N_timePoints
- graph_num = (i-1)*N_detector + j;
- if j == 1
- legend_num(i) = graph_num;
- end
- g(graph_num) = plot(j, velocity(i, j));
- g(graph_num).LineStyle = 'none';
- g(graph_num).Marker = shape{i};
- g(graph_num).MarkerEdgeColor = col{j};
- g(graph_num).MarkerFaceColor = col{j};
- g(graph_num).MarkerSize = 8;
- text(j + 0.1, velocity(i, j), ['\leftarrow v_', num2str(i), '(t_', num2str(j), ')'])
- if i == 1 && j == 1
- hold on;
- end
- end
- end
- hold off
- graph = gca;
- graph.XTick = 1:N_timePoints;
- graph.XTickLabel = cellstr([repmat('t_', N_timePoints, 1), num2str((1:N_timePoints)')]);
- legend(g(legend_num), cellstr([repmat('detector ', N_detector, 1), num2str((1:N_detector)')]), 'Location', 'northwest')
- xlim([0.5, N_timePoints + 0.8])
- ylim([20, 80])
- xlabel('Time')
- ylabel('Velocity')
- fig.Units = 'centimeters';
- fig.PaperPosition = [0,0,15,15];
- saveas(gcf, 'graph_20151028/init.png')
- %% second graph - velocity v.s. location
- clear g
- fig2 = figure;
- legend_num = zeros(N_timePoints, 1);
- for i = 1:N_detector
- for j = 1:N_timePoints
- graph_num = (i-1)*N_detector + j;
- if i == 1
- legend_num(j) = graph_num;
- end
- g(graph_num) = plot(detector_location(i), velocity(i, j));
- g(graph_num).LineStyle = 'none';
- g(graph_num).Marker = shape{i};
- g(graph_num).MarkerEdgeColor = col{j};
- g(graph_num).MarkerFaceColor = col{j};
- g(graph_num).MarkerSize = 8;
- text(detector_location(i) + 1, velocity(i, j), ['\leftarrow v_', num2str(i), '(t_', num2str(j), ')'])
- if i == 1 && j == 1
- hold on;
- end
- end
- end
- hold off
- graph = gca;
- graph.XTick = detector_location;
- graph.XTickLabel = cellstr([repmat('detector ', N_detector, 1), num2str((1:N_detector)')]);
- legend(g(legend_num), cellstr([repmat('t_', N_timePoints, 1), num2str((1:N_timePoints)')]), 'Location', 'northwest')
- xlimRange = [min(detector_location) - 0.2*range(detector_location), max(detector_location) + 0.3*range(detector_location)];
- xlim(xlimRange)
- ylim([20, 80])
- for i = 1:(N_detector-1)
- loc_text = mean(detector_location(i:i+1));
- text(loc_text, 22, ['l_', num2str(i)])
- text(loc_text-1, 24, ['TT_', num2str(i)])
- text(detector_location(i), 23, '|\leftarrow')
- text(detector_location(i+1)-1.5, 23, '\rightarrow|')
- end
- xlabel('Locations of Detectors')
- ylabel('Velocity')
- fig2.Units = 'centimeters';
- fig2.PaperPosition = [0,0,15,15];
- saveas(gcf, 'graph_20151028/init_2.png')
Advertisement
Add Comment
Please, Sign In to add comment