Writematrix command not writing data in my excel sheet

sname='Sheet1';
startingColumn='A';
nextRow='1';
filename = 'C:\Users\vvb\Documents\New\ltp.xlsx';
ltp_hist_uper=hist(ltp_uper,10);
ltp_hist_lower=hist(ltp_lower,10);
ltp_full=[ltp_hist_uper ltp_hist_lower]; % contatinate both uper and lower vectors
range=sprintf('%s%d',startingColumn,nextRow);
writematrix(ltp_full,filename,sname,range);
I have download this code for extracting features from an audio file and want to store those features in Excel file which is ltp.xlsx but writematrix command is throwing an error i.e. Invalid parameter name: Sheet1

Réponses (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi le 23 Août 2020
Modifié(e) : Abdolkarim Mohammadi le 23 Août 2020
You should pass sheet name and range as a Name-Value pair argument:
writematrix (ltp_full, filename, 'Sheet', sname, 'Range', range)
Read the documentation of readmatrix():
https://www.mathworks.com/help/matlab/ref/writematrix.html

6 commentaires

Ralph
Ralph le 24 Août 2020
Modifié(e) : Ralph le 24 Août 2020
The code is working fine now but my values are not updated in ltp.xlsx file as intended.
Do values in Excel differ from MATLAB? Or you get error in MATLAB?
Ralph
Ralph le 24 Août 2020
I have exactly copy and pasted the above code my code is working fine though my Excel/xlsx sheet is not being updated with values.
range=sprintf('%s%d',startingColumn,'A1:T1');
writematrix(ltp_full, filename,'Sheet', sname, 'Range',range);
I have manually inserted the row names which is 'A1:T1' its working fine now but it is not working with the nextrow funciton.
Ralph
Ralph le 24 Août 2020
I want my code to dyanmically allocate values to rows
Your code should work fine with any input, since ltp_full has a fixed dimension of 10x2. If this dimension is being changed within a loop, it is better to first clear the destination cells for shorter matrixes to be better observed.

Connectez-vous pour commenter.

Catégories

Question posée :

le 23 Août 2020

Community Treasure Hunt

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

Start Hunting!

Translated by