필터 지우기
필터 지우기

Using container map to get values and to draw histogram

조회 수: 6 (최근 30일)
Ntombikayise Bhengu
Ntombikayise Bhengu 2020년 10월 12일
답변: Puru Kathuria 2020년 10월 23일
M =
Map with properties:
Count: 100
KeyType: char
ValueType: double
mean(valueSet)
ans =
1.3911e+07
I have the above container map. Howdo I get values of
+ Histogram
+ Most common letter of first name
+ Average number of letters in first name (integer)
  댓글 수: 1
Ntombikayise Bhengu
Ntombikayise Bhengu 2020년 10월 12일
I did the histogram using the followig code:
bar(valueSet)
got this drawing:

댓글을 달려면 로그인하십시오.

답변 (1개)

Puru Kathuria
Puru Kathuria 2020년 10월 23일
Hi,
I understand that you are storing your data in containers.Map and want to plot it as a bar graph.
Below is the code snippet that explains how to plot bar graphs on Maps and also shows how to query the most occuring key in the data.
I hope you can relate the below demonstration to your requirements
%Plotting bar graph
keysData = {'a', 'b', 'c', 'e', 'g'}; valuesData = [1,3,4,5,8];
map = containers.Map(keysData,valuesData);
bar(cell2mat(map.values));
k = keys(map);
set(gca, 'XTick', 1:length(k));
set(gca, 'XTickLabel', k);
%Finding most occuring character
keySet = cell2mat(map.keys);
maxFrequency = 0;
maxKey = '';
for i = 1:numel(keySet)
iThValue = map(keySet(i));
if iThValue >= maxFrequency
maxFrequency = iThValue;
maxKey = keySet(i);
end
end
maxKey
maxFrequency

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by