How can I write in excel multiple columns as vectors?

First of all, thanks for reading this. Well, I have a gui that writes columns in a new excel spreadsheet concatenating them in a matrix, but I don't know how many columns will the user write in that excel file. I'm using xlswrite.
The sintax that I think I could use for concatenation is:
Y=[X1,X2,X3,...,Xn]
I hope I had been explicit with my question. Greetings.

Réponses (2)

Sara
Sara le 8 Juil 2014
You can create dynamically the range to write to. For instance, starting from A1:
xlswrite('myfile.xlsx',Y, ['A1:',char(64+size(Y,2)),':',num2str(size(Y,1))])
Image Analyst
Image Analyst le 8 Juil 2014
Modifié(e) : Image Analyst le 8 Juil 2014
Simply create your Y any way you'd like, such as you did. Then call xlswrite
xlswrite(filename, Y, 'A1');
'A1' is the upper left cell in Excel where you want to put the upper left cell of your array - you can make it whatever/wherever you want. It doesn't care how many rows or columns are in Y - it will put them all in there. You don't need to do what Sara did, and you don't need to specify the lower right cell unless you want to export just a portion of Y and not the full array.

9 commentaires

Sara
Sara le 8 Juil 2014
I didn't know you could just specify the upper corner, that's useful to know.
Edgar
Edgar le 9 Juil 2014
I know how to write the final Y in matlab but, how can I save all the undefined number of vectors that I want to concanate in Y? With a for or while loop? Thanks.
Sara
Sara le 9 Juil 2014
I don't understand, if those vector are in Y, what do you need?
Edgar
Edgar le 9 Juil 2014
Concatenate an undefined number of vectors in Y
Sara
Sara le 9 Juil 2014
Let's start over. How are those arrays created by the user? How do you get them? Is that thru a GUI, an input excel file, command window,...?
Do you have the Xn or not? Do you have the Y or not? If you just want to append some variable number, then use
Y = [Y, thisX]; % Tack on thisX.
For example if you want to make Y the columns between 4 and 9 of some array:
for col = 4 : 9
thisX = array2d(:, col);
if col == 4
Y = thisX; % First column so initialize - nothing to append onto yet.
else
Y = [Y, thisX]; % Append/stitch on thisX to existing Y.
end
end
Edgar
Edgar le 9 Juil 2014
From an excel spreadsheet that contains variables (vectors), The user select one of them, then he does an operation with that variable, creating a new variable that will be concatenated in Y, but this process is done by the user until the user leave from the GUI.
Sara
Sara le 9 Juil 2014
Once the new variable is created, you can concatenate that directly to Y, which will be saved as a field of handles as handles.Y and print it out when the user leaves the GUI. You'll need to create handles.Y = [] in the gui opening function and keep concatenating all the variables the user creates. Is that clear, is that what you want?
Edgar
Edgar le 11 Juil 2014
This is what I need, thank you Sara.

Connectez-vous pour commenter.

Question posée :

le 8 Juil 2014

Commenté :

le 11 Juil 2014

Community Treasure Hunt

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

Start Hunting!

Translated by