필터 지우기
필터 지우기

How can I count and plot

조회 수: 15 (최근 30일)
Sanghyeon Chang
Sanghyeon Chang 2023년 5월 10일
답변: Jaswanth 2024년 1월 5일
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.

답변 (1개)

Jaswanth
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:
  1. ‘readmatrix’:https://www.mathworks.com/help/matlab/ref/readmatrix.html
  2. ‘bar’:https://www.mathworks.com/help/matlab/ref/bar.html
  3. ‘cumsum’:https://www.mathworks.com/help/matlab/ref/cumsum.html
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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by