MATLAB Answers

How do I calculate percentage or frequency and display it on a bar plot?

조회 수: 7(최근 30일)
Danai Varvatsouli
Danai Varvatsouli 3 Jul 2020
답변: Steven Lord 3 Jul 2020
Hello I have an excel file with 48 land types and a image.tif of a country, and I want to calculate the Frequency (how many times each land type of the excel appear on the tif.iamge), and also the percentage of Frequency which is: Percentage=(Frequency/Total Frequency)*100.
I have calculated the frequency but does anyone know how to calculate the rate?? I tried
total = sum(frequency);
rate=(frequency/total):100;
It gives me results 48 times, as many times as my land types. How do I correct that?
Also I have to make a bar plot for the percentage results using colorbar.
Any ideas?

  댓글 수: 0

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

답변(2개)

the cyclist
the cyclist 3 Jul 2020
Because you have the typo
rate=(frequency/total):100;
instead of
rate=(frequency/total)*100;

  댓글 수: 3

Danai Varvatsouli
Danai Varvatsouli 3 Jul 2020
Sorry I made the typo here. In my matlab code is * But still doesn't work. It is displaying 48 times. Any ideas how to make a bar plot that will display only the rates with colorbar?
the cyclist
the cyclist 3 Jul 2020
It's not really possible to help debug plotting code that you don't show us. Can you upload the files needed for us to reproduce the error you are seeing?
the cyclist
the cyclist 3 Jul 2020
I also notice you keep saying "colorbar". If you are really trying to use the colorbar command to make a chart, you should be using bar instead.

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


Steven Lord
Steven Lord 3 Jul 2020
Use histogram with 'probability' as the value for the 'Normalization' option.

  댓글 수: 0

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


Translated by