Matlab questions: Read from Excel file

  • Context: MATLAB 
  • Thread starter Thread starter pp84
  • Start date Start date
  • Tags Tags
    Excel File Matlab
Click For Summary

Discussion Overview

The discussion revolves around using MATLAB to read data from Excel files, specifically focusing on cycling through different sets of data and dynamically adjusting the range of data read from the files. The scope includes programming techniques and function usage within MATLAB.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • The original poster (OP) seeks assistance with a MATLAB program that cycles through data sets stored in Excel files and applies a function to each variable.
  • The OP wants to know if it's possible to replace a fixed number in the xlsread function with a variable to avoid manual changes across multiple instances.
  • One participant suggests using string concatenation to dynamically create the range string for xlsread, providing an example of how to implement this.
  • Another participant notes that as of R2019a, MATLAB no longer recommends using xlsread and suggests using readmatrix instead.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the best approach to the OP's questions, and there are differing opinions on the use of xlsread versus readmatrix.

Contextual Notes

The discussion does not clarify the specific limitations of the proposed solutions or the implications of transitioning from xlsread to readmatrix.

pp84
Messages
4
Reaction score
0
Hi,
Looking for a bit of cheeky help with matlab, I am stumped!

1) I have written a program that i want to cycle through different sets of data, ideally this is what i would like:
These are all xls files with columns of data

ydata = ...
xdata = ...
zdata = ...

for variable = ydata:xdata:zdata
do function to each of the variables seperatly
write function results(variable) and save data
end

Is this possible?

2) When calling a file name eg:

[FTSE] = xlsread('Normalised Smooth Data.xlsx', 'FTSE', 'A1:A300')

I want to replace 300 with a variable rather than changing many of them manually everytime i need to change that number, so i would have something like this:

numberofpoints = 300
[FTSE] = xlsread('Normalised Smooth Data.xlsx', 'FTSE', 'A1:Anumberofpoints')

Again, is this possible? I am sure it is i just don't know the key commands.

Any help would be much appretiated.

Thanks

Punit
 
Physics news on Phys.org
OP last seen in 2010. Anyone want to take a crack at it, anyway!
 
One way of doing this would be to use string concatenation to construct the relevant string, i.e., do something like
Code:
N = 300;
str = strcat('A1:A',int2str(N));
You can then use the str variable instead of 'A1:A300' in your original code (or you can put the strcat and everything in its argument as the argument of xlsread directly).
 
  • Like
Likes   Reactions: Wrichik Basu
Note that as of R2019a, Matlab no longer recommends the xlsread function. Use readmatrix instead.
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
2
Views
8K
Replies
1
Views
6K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
2K