How to find next empty row in Excel Worksheet?

Hi,
I am trying to write a matlab code which allows data to be implemented into an Excel spreadsheet at the next available row.
Currently I have been using the code below which allows me to input data to excel cells that i specify. In the long run i want matlab to automatically find the next available row and implement data into columns of that row. I dont really know how to do this and am fairly new to Matlab so would appreciate any help. (the code below is a very simple version of what I am trying to do)
Fx = 10
Fy = 20
Fz = 30
filename = 'filtereddata.xlsx';
xlswrite(filename,Fx,'Sheet1','A1')
xlswrite(filename,Fy,'Sheet1','B1')
xlswrite(filename,Fz,'Sheet1','C1')

댓글 수: 4

Calling xlswrite for each line of a matrix is horribly inefficient, and it is generally practiced to minimize the number of times you have to call xlswrite or xlsread. It is sometime unavoidable to call these commands multiple times in a script, but people do like to avoid doing so if possible.
All that leads me to these questions: Why are you trying to write multiple sets of data to a spreadsheet individually? Is it not possible to write one large matrix?
Hi Bob
When i run it properly i will be doing it as a large matrix or table and only calling it through once not several times. This is me just trying to work out how i would go about doing what I want to do on a much simpler scale.
Would you recommend any function or type of code that would establish the next available row in an excel spreadsheet and then store the data, table, matrix, array etc to that row?
thanks in advance
A simple way of doing this would be to read the data that is in the excel sheet and then simply adjust the write dimensions to be past that. This can be a bit of a memory hog, but if you are only reading and writing once you should be ok.
[~ ~ complete] = xlsread('myspreadsheet.xlsx');
lr = size(complete,1);
range = ['A',num2str(lr+1)];
xlswrite('myspreadsheet.xlsx',mydata,range);
thank you so much

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

태그

질문:

2019년 4월 15일

댓글:

2019년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by