matlab to excel back to matlab

1 次查看(过去 30 天)
kelsey
kelsey 2013-4-6
Ok so I am doing this side project for someone and I have never dealt with the combination of matlab and excel. I read up a lot about how to write in excel but I am hitting some barriers.
I have an excel file that is called, "ExcelData.xlsx" and there are very complex analytical equations within the excel sheet. So there are specific cells in the sheet that have #s and if you change their numbers than the solutions to the equations located in other cells changes and then those cause the graphs within the excel sheet to change. So I need to be able to write a matlab program that changes (overwrites) 3 separate cells with data from user input in matlab. The cells that need to change are A3, A57, and A60. Then to make it even more difficult once the #s change and the excel sheet updates itself I need to be able to retrieve all of the data from specific columns in the excel sheet and read it back into matlab so that I can create my own plots rather than having the graphs from excel. I know how to create plots in matlab I just don't know how to use excel data to do so.
Can anyone help me with this crazy program. I feel like it isn't that hard but I am having trouble with connecting excel and matlab.
So here are my opening input prompts: I don't know where to begin after this.
prompt2={'Concentration of Glucose (mM)?','Concentration of ATP (mM)?','Concentration of pyruvate (mM)?'};
dlg_title2='Aerobic Bioreactor Parameters';
num_lines=1;
def={'INSERT HERE','INSERT HERE','INSERT HERE'};
A2=inputdlg(prompt2,dlg_title2,num_lines,def);
glu=str2num(A2{1});
atp=str2num(A2{2});
pyr=str2num(A2{3});
Thank you so much ahead of time for anyone that can help be fumble through this.

回答(1 个)

Ahmed A. Selman
Ahmed A. Selman 2013-4-7
So you want to write a program in Matlab that writes 3 values in 3 cells in an Excel file? OR you need to read 3 cells from an excel file then change them with Matlab then re-write them in the excel. If so then perhaps you don't need a code, I mean how tough it is to change 3 single cells in an excel file?
If your problem is more complicated than this, then please skip the excel (#s) details and try this at the end of your code:
xlswrite('ExcelData.xlsx',glu,'A3');
xlswrite('ExcelData.xlsx',atp,'A57');
xlswrite('ExcelData.xlsx',pyr,'A60');
This overwrites the values in resp. A3, A57 and A60 and writes glu, stp and pyr variables' values (they are numbers), maybe you want to use (str2double) function instead of (str2num). The reference for the function xlswrite is
and it's easier to work with than you thought. This is the part about (writing data in Excel). A similar easy function, xlsread, is used to read them from the file, found in:
Tip: In MS Excel you can use (insert chart) to plot data, then select (series) each of which are containing, usually, (x-y) data. After you plot the curve you can right-click anywhere (chart area, line, axes, titles, labels.. etc) and change whatever you need (color, weight, size, even chart type, or data range).
Regards.

Community Treasure Hunt

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

Start Hunting!

Translated by