how to find out the number of operating points in a scattered graph for specific interval and plot the occuring number as circles or histogram (shown in pic below)?
1 次查看(过去 30 天)
显示 更早的评论
I have the following torque vs speed graph of a vehicle. How can I get the number of points between different intervals of speed, for example (for every interval of 1 km/h, interval of 10 km/h and so on)? Please help me. Thanks in advance. this is the code that generates the graph.
load('Drp_WLTC_v5.mat')
t = Drp_vCycle_CUR.Drp_tiCycle_AXIS; % s v = Drp_vCycle_CUR.Drp_vCycle_GCUR; % km/h a = [0 diff((v/3.6))./diff(t)]; % m/s² figure_n = round(rand(1)*100000); figure_n = figure(figure_n); hold on set(gcf,'Color',[1 1 1],'units', 'centimeters', 'pos', [10 5 26 13]) subplot(2,1,1) plot(t,v,'linewidth',1.75,'color',[0 191 255]./255)
xlabel('Time in s',... 'FontSize',15,... 'FontName','Arial');
ylabel('velocity in km/h',... 'FontSize',15,... 'FontName','Arial');
set(gca,'Parent',figure_n,'FontSize',13,'FontName','Arial'); grid on subplot(2,1,2) plot(t,a,'linewidth',1.75,'color',[0 191 255]./255)
xlabel('time in s',... 'FontSize',15,... 'FontName','Arial')
ylabel('acceleration in m/s²',... 'FontSize',15,... 'FontName','Arial');
set(gca,'Parent',figure_n,'FontSize',13,'FontName','Arial');
grid on name_plot = 'WLTC.emf'; set(gcf, 'PaperPositionMode', 'auto'); saveas(gcf,name_plot)
%%
v_uq = unique(v); a_uq = unique(abs(a)); % Case 1 - motoric & generatoric ca{1}.dat = v>v_uq(2) | abs(a)>a_uq(2); ca{1}.name = 'abs(acc. & dec.)';
% Case 2 - motoric ca{2}.dat = v>v_uq(2) & a>a_uq(2); ca{2}.name = 'acc.'; % Case 3 - generatorix ca{3}.dat = v>v_uq(2) & a<-a_uq(2); ca{3}.name = 'dec.';
%%
d_hist = 20;
% Vorgabe der colorbar Farbe n_lin = 100; t_col = [0 191 255]; cmap = [linspace(255,t_col(1),n_lin)' linspace(255,t_col(2),n_lin)' linspace(255,t_col(3),n_lin)']./255; % doubt why 255? t_col = [0 0 0]./255; n_lin = 50; cmap2 = [linspace(cmap(end,1),t_col(1),n_lin)' linspace(cmap(end,2),t_col(2),n_lin)' linspace(cmap(end,3),t_col(3),n_lin)'];
cmap = [cmap(1:end-1,:) cmap2];
for ii = 1:length(ca)
% Anwendung der 'Cases' auf die Daten
v_pl = v(ca{ii}.dat);
a_pl = a(ca{ii}.dat);
if ii == 1
a_pl = abs(a_pl);
end
dat = [v_pl' a_pl'];
% number of points
numberOfGoodPoints = sum(~isnan(v_pl) & ~isnan(a_pl))
% Histogramm
[count, edges] = histcn(dat,20,20); %%doubt.. why?
% Normierung
count = count/sum(sum(count))*100; %%gives frequency distribution
ca{ii}.count = count;
% Diskretisierungwerte des Histogramms
edge.a = edges{1,2}; % acceleration variable
edge.v = edges{1,1}; % velocity variable
ca{ii}.edge.a = edge.a;
ca{ii}.edge.v = edge.v;
figure_n = round(rand(1)*100000);
figure_n = figure(figure_n);
set(gcf,'Color',[1 1 1],'units', 'centimeters', 'pos', [10 5 13 10]);
% imagesc(edge.v,edge.a,count'); % Angabe mitte des Feld
pcolor(edge.v,edge.a,count'); % Angabe unten links
grid on;
colormap(cmap) % heat map
% cb = colorbar('peer',gca,'vert');
cb = colorbar %('peer',gca,'vert');
zlab = get(cb,'ylabel');
set(zlab,'String','frequency in %',...
'FontSize',15,...
'FontName','Arial');
xlabel('speed in km/h',...
'FontSize',15,...
'FontName','Arial')
ylabel('acceleration in m/s²',...
'FontSize',15,...
'FontName','Arial');
set(gca,'Parent',figure_n,'FontSize',13,'FontName','Arial');
name_plot = [strrep(ca{ii}.name,'.','_'), '.emf'];
set(gcf, 'PaperPositionMode', 'auto');
saveas(gcf,name_plot)
count2 = reshape(count,size(count,1)*size(count,2),1);
v_2 = repmat(edge.v',size(count2,1)/length(edge.v),1);
a_2 = sort(repmat(edge.a',size(count2,1)/length(edge.v),1),'ascend');
mtx = [count2 v_2 a_2];
ca{ii}.mtx = mtx;
mtx = sortrows(mtx,1);
disp('--------------------------')
disp(ca{ii}.name)
disp('% km/h m/s²')
disp(num2str(mtx(end-2:end,:)))
disp('')
ca{ii}.op = mtx(end-2:end,:);
%%%Arbeitspunkte
figure_n = round(rand(1)*100000);
figure_n = figure(figure_n);
a_pl = a(ca{ii}.dat);
set(gcf,'Color',[1 1 1],'units', 'centimeters', 'pos', [10 5 13 10]);
plot(v_pl,a_pl,'x','color',[0 191 254]./254)
xlabel('speed in km/h',...
'FontSize',15,...
'FontName','Arial')
ylabel('acceleration in m/s²',...
'FontSize',15,...
'FontName','Arial');
set(gca,'Parent',figure_n,'FontSize',13,'FontName','Arial');
grid on
name_plot = [strrep(ca{ii}.name,'.','_'), '_operations_points.emf'];
set(gcf, 'PaperPositionMode', 'auto');
saveas(gcf,name_plot)
end
<<
<<
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164394/image.png)
>>
>>
1 个评论
Jan
2017-5-24
As far as I understand, the problem you ask for has no connection to the huge unreadable code or the figures. Then please do not post so many unrelated information.
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!