Sunday, 15 February 2015

user interface - Using xlswrite to save data from an array? Matlab -



user interface - Using xlswrite to save data from an array? Matlab -

i have created gui matlab , @ end of user has alternative save info , saves excel file chose. theres 2 seperate sets of info saved , written excel file. first 1 1 numerical value intensityvalue2 such 4592.25 , otherauc2 array of different numerical values such [] [5025.8] [5012.3] [4963.45] here code using:

% --- executes on button press in save. function save_callback(hobject, eventdata, handles) % hobject handle save (see gcbo) % eventdata reserved - defined in future version of matlab % handles construction handles , user info (see guidata) intensityvalue = getappdata(0,'iv'); [filename,pathname]= uigetfile('*.xlsx*','file save to'); intensityfile = fullfile(pathname,filename); filename = intensityfile; mypeak = {'peak(nm)'}; xlswrite(filename,mypeak,'sheet1','a1'); myintensity = {'intensity'}; xlswrite(filename,myintensity,'sheet1','b1'); intensityvalue2 = str2num(intensityvalue); xlswrite(filename,intensityvalue2,'sheet1','b2'); otherauc = getappdata(0,'auc') numfiles = getappdata(0,'files'); = 2:numfiles otherauc2{a} = otherauc{a} end xlswrite(filename,otherauc2,'sheet1','b3');

at moment excel file looks this:

peak(nm) intensity 4592.25 5025.8 5012.3 4963.45

whereas this:

peak(nm) intensity 4592.25 5025.8 5012.3 4963.45

can help me accomplish this? realise first cell empty in otherauc2but thought foor loop have meant first cell not written excel file. help or suggestions appreciated!

just recap:

when xlswrite writes info excel file, layout same layout in matlab. if have 1x4 array write 1 row , if have 4x1 array write 1 column. reshape array can utilize matlab's transpose function, abbreviated .' (complex conjugate) or ' (transpose). 3 equivalent in case.

so application have 2 methods:

otherauc2 = otherauc2.'; xlswrite(filename,otherauc2,'sheet1','b3'); % or xlswrite(filename,otherauc2.','sheet1','b3');

both methods should give result you're looking for.

for sec part, for loop needs tweaked. right start loop index @ 2 in order skip blank value, forgot business relationship index shift in new array.

all need subtract 1 otherauc2 index:

for = 2:numfiles otherauc2{a-1} = otherauc{a} end

alternatively, can delete empty cells without loop:

otherauc = otherauc(~cellfun(@isempty, otherauc));

cellfun applies specified function each cell in cell array, eliminates need loops in many situations. here it's doing going through each cell , seeing if it's empty. redefines otherauc every cell not empty. illustration of logical indexing (~cellfun(@isempty, otherauc) returns 1x4 logical array, false empty cell).

you can accomplish same thing numerical array:

test = [nan,2,3,4]; test(isnan(test)) = []; % or test = [0,2,3,4]; test(test==0) = [];

just careful floating point errors when comparing non-integers , not using tolerance.

matlab user-interface xls

No comments:

Post a Comment