Read and write data in Excel using matlab

조회 수: 6 (최근 30일)
Alan Smith
Alan Smith 2015년 4월 19일
답변: sunitha 2020년 12월 19일
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
Image Analyst
Image Analyst 2015년 4월 19일
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.
Alan Smith
Alan Smith 2015년 4월 19일
Oh sorry, that was my mistake, the code is interpolating the data from the excel file called (testdata.xlsx), and yes the temperature and pressure will be in known constant columns for each sheet so i guess i could edit that to it, but I have no idea how to change it will perform the calculation on multiple sheets

댓글을 달려면 로그인하십시오.

답변 (1개)

sunitha
sunitha 2020년 12월 19일
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..

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by