How to find the last column index in excel with Matlab

后端 未结 2 900
清歌不尽
清歌不尽 2020-12-11 14:19

I am writing data as matrices into excel file using Matlab. My matrices\' dimension varies and I don\'t know the matrices\' dimension in advance. Let\'s say I have matrix A,

2条回答
  •  悲&欢浪女
    2020-12-11 14:58

    You could try something like:

    cellVector= ['A2';'B2';'C2';'D2';'E2']; %...etc as many as you need
    cellstart = 'B2';
    cellVectorLoc = find(cellVector == cellstart(1)); % Finds where B is located in cellVector  
    xlswrite('My file.xls',A,'My Sheet',cellstart);
    nextCellLoc = length(A) + cellVectorLoc + 1; % length of A plus location in index + 1 for blank column.  I can't remember if you should use length() or size().
    newIndex= cellVector(nextCellLoc,:); % new index
    xlswrite('My file.xls',B,'My Sheet',newindex);
    

    Just be aware, this won't work for cells after column Z, because, for example, cellVectorLoc = find(cellVector == cellstart(1)); will find two locations in cellVector for column 'AA'.

    Also, I can't remember if length(A) or which element of size(A) refers to the number of columns in A. Play around with the other one if length(A) doesn't give you the correct number of cols.

提交回复
热议问题