MATLAB Answers

My Excel writing program does not stop

1 view (last 30 days)
Sadiq Akbar
Sadiq Akbar on 21 Feb 2020
Commented: Sadiq Akbar on 4 Mar 2020
I have two arrays of vextors V1 and V2. Array V1 has 100 row vectos and array V2 has 100 row vectors. i,e, each vector is a row vector and is of 4 elements, i.e.
V1=[1 2 3 4]
[2 1 4 1]
[15 8 0]
upto 100
V2=[1 5 7 9]
[1.2 3.4 5.1 6.1]
[2.4 6.1 7.1 9.2]
up to 100
I want to write vectors of array V1 in column A and vectors of array2 in column D of excel file.I have written the following program:
for n=1:100
for jj=1:size(strV1,1)
xlswrite(filename, cellstr(strV1(jj,:)), 'Sheet1', ['A',num2str(jj)]);
for ll=1:size(strV2,1)
xlswrite(filename, cellstr(strV2(ll,:)), 'Sheet1', ['D',num2str(ll)]);
The above program works well, but it does not stop by itself. it continues to run even if you allow it to run for several days. I want that when the task is finished, the program stops automatically because often I have to press CTRL+C several times, only then it stops and when I check the excel file, it has written those vectors already but still it continues to run. What is the problem with this program?


darova on 21 Feb 2020
Why can't you just write all values with one command?
V = 1:10;
Sadiq Akbar
Sadiq Akbar on 22 Feb 2020
As I told you I have array of vecttors, i.e. each element of the array V is a row vector. I want to write one row vector in A1 cell of Excle file. 2nd row vector in A2 cell of Excel file, 3rd row vector in A3 of Excel file and so on. I don't want to make each vector as column vector and write them in separate columns. But rather I want to write each row vector of the array in one cell, then 2nd row vector in 2nd cell of the same column, then 3rd row vector in 3rd cell of the same column and so on.
Guillaume on 1 Mar 2020
"I want to write one row vector in A1 cell of Excle file"
While that's easy to do (without any loop as well), why on earth would you want to do that? Indeed, the numbers would have to be changed to text in excel, so they would be completely unusable with any formula. It doesn't sound like you'll be using excel the way it's meant to be used so there's probably a better way of achieving your end goal. What is your end goal?

Sign in to comment.

Accepted Answer

darova on 23 Feb 2020
Edited: darova on 23 Feb 2020
It this a success?
V1 = randi(100,5,5);
for i = 1:size(V1,1)
vv1 = { num2str(V1(i,:)) };
xlswrite('data.xls',vv1,'sheet1',['B' num2str(i+1)])
I gave an idea from here


darova on 3 Mar 2020
  • But how can I become expert like you?
practice, practice ...
Stephen Cobeldick
Stephen Cobeldick on 3 Mar 2020
"But how can I become expert like you?"
reading documentation, reading documentation...
Sadiq Akbar
Sadiq Akbar on 4 Mar 2020
Thank you very much darova and Stephen Cobeldick for your useful suggestions. Indeed both of you are right. I will try my best in sha Allah.

Sign in to comment.

More Answers (0)