Read and write data in Excel using matlab
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have a set of data in excel that needed to be interpolated based on two variables called temperature and pressure. The code I have will read the interpolated data from one excel file(called testdata.xlsx), check the the temperature and pressure values in the excel file (results.xlsx)
The code will then place the interpolated answer in the third column of the excel sheet (results.xlsx). What I need is the ability to tell matlab which column the temperature comes from, which column the pressure comes from and which column to write the results in.
But on top of that I'd need it do this on all sheets as on my real results file there is a different temperature and pressure to calculate the interpolated data from. The columns temperature and pressure will be in will be the same for each sheet
Below are example excel files and current code
https://www.dropbox.com/s/0l6b1ngu1qszavj/results.xlsx?dl=0 https://www.dropbox.com/s/dbuzncyr5ie912y/testdata.xlsx?dl=0
if true
%%%%%%%
clear all
close all
fprintf('\n No excel files must be open when running the script')
fprintf('\n All files must be in current directory with the script File names \nare case sensitive and require extensions which are appropriate')
filename1=input('\n Enter the filename to read data from with\n extension (ex. testdata.xlsx) : ','s');
filename2=input('\n Enter the filename having values to which the \ndata is to be interpolated with extension (ex. results.xlsx ) : ','s');
data=xlsread(filename1);
xdata=data(1,2:end);
ydata=data(2:end,1);
V=data(2:end,2:end);
data2=xlsread(filename2);
xq=data2(:,1);
yq=data2(:,2);
str1=num2str(length(xq)+1);
rangeis=strcat('C2:C',str1);
intval=interp2(xdata,ydata,V,xq,yq);
xlswrite(filename2,intval,rangeis)
fprintf('\n Result written in third column of file %s (Re open to see it)(blank spaces means not a number )',filename2)
end
3 Commenti
Image Analyst
il 19 Apr 2015
Why can't you make sure the temperature and pressure are in known, constant column numbers? Do they occur in random columns in each worksheet and workbook?
You said this: "read the interpolated data from one excel file(called testdata.xlsx)", which to me seems to say that the data are already interpolated in your input worksheet.
Instead of using interp2, you can just use imresize() if you have the Image Processing Toolbox.
Risposte (1)
sunitha
il 19 Dic 2020
Hii, I am new to MATLAB.i have used a set of data in the excel. I have imported the excel data in the matlab.i don't know how to write a code for performing arthimetic operatios using data . I want to calculate the values theta*X/So-S and 1/S values. I want the plot the linear graph for these values. I am attaching the excel data below..
0 Commenti
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!