How to access much data from excel sheet to matlab?

1 次查看(过去 30 天)
fileName = 'try.xlsx'; a = xlsread(fileName); x = a(:,1); y = a(:,60); plot(x,y)
I am getting error as: Attempted to access a(:,60); index out of bounds because size(a)=[59,8].

回答(1 个)

Prateekshya
Prateekshya 2024-8-21
Hello Manish,
The error indicates that there are 59 rows and 8 columns in the excel file however, you are trying to access 60th column. For getting rid of this error, please make sure you are accessing elements within the available range that is a(1,1) to a(59,8).
Here is an example to do the same:
% Read data from the Excel file
fileName = 'try.xlsx';
a = xlsread(fileName);
% Check the size of 'a' to understand its dimensions
disp(size(a)); % This will display the number of rows and columns
% Correct the column indices based on the actual data
x = a(:, 1); % Assuming the first column is correct
y = a(:, 8); % Adjust this to the correct column index, e.g., 8 instead of 60
% Plot the data
plot(x, y);
xlabel('Column 1');
ylabel('Column 8'); % Adjust the label according to the actual data
title('Plot of x vs. y');
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by