- ‘readmatrix’:https://www.mathworks.com/help/matlab/ref/readmatrix.html
- ‘bar’:https://www.mathworks.com/help/matlab/ref/bar.html
- ‘cumsum’:https://www.mathworks.com/help/matlab/ref/cumsum.html
How can I count and plot
조회 수: 15 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1379199/image.png)
If I have a excel file looks like this, I'd like to plot time vs total number of count as shown below.
y-axis is the number of counts, while x-axis is the range.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1379204/image.png)
댓글 수: 0
답변 (1개)
Jaswanth
2024년 1월 5일
Hi,
I understand that you wish to extract data from an Excel file and display it in a chart format similar to the one you provided. To achieve this, you can import the data from Excel using the ‘readmatrix’ function and create a bar chart with the ‘bar’ function. If you need to calculate a running total over time, the ‘cumsum’ function can be utilized. It computes the cumulative sum of the elements, beginning from the start of the first array dimension with a size larger than 1.
Please go through the following MathWorks documentation to know more about the functions mentioned above:
Please go through the following example code showing how to plot from an Excel file using a bar chart in MATLAB.
% Assume the Excel file is named 'data.xlsx' and the data is in the first sheet
% The time data is in the first column and the count data is in the second column
% Read the table from the Excel file
data = readtable('data.xlsx');
% Extract the time data
time_data = data{:, 1};
% Extract the count data
count_data = data{:, 2};
% Replace empty cells or NaN values with zeros
count_data(isnan(count_data)) = 0;
% Calculate the cumulative total count
cumulative_count_data = cumsum(count_data);
% Create a bar chart
bar(time_data, cumulative_count_data);
% Set the labels and title
xlabel('Time');
ylabel('Cumulative Total Count');
title('Cumulative Count vs. Time from Excel Data');
Hope the above provided information is helpful.
Thanks.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!