MATLAB Matlab questions: Read from Excel file

AI Thread Summary
The discussion revolves around two main issues related to MATLAB programming. The first issue involves cycling through different sets of data stored in Excel files. The user seeks to implement a loop that processes variables defined by data columns, aiming to apply a function to each variable and save the results. The second issue pertains to dynamically specifying a range in the xlsread function, where the user wants to replace a fixed number with a variable to avoid manual changes in multiple instances. A suggested solution involves using string concatenation to create the desired range string, allowing for the use of a variable instead of a hardcoded number. Additionally, it is noted that as of MATLAB R2019a, the xlsread function is no longer recommended, and users should switch to using readmatrix for reading data from Excel files.
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 Wrichik Basu
Note that as of R2019a, Matlab no longer recommends the xlsread function. Use readmatrix instead.
 

Similar threads

Replies
18
Views
6K
Replies
5
Views
8K
Replies
4
Views
6K
Replies
3
Views
3K
Replies
4
Views
7K
Back
Top