Turining individual element to a matrix

2 次查看(过去 30 天)
I wrote a function to accept an excel file (file attached) and to find from the temperature column (20:5:71)+- 0.05 and take the mean of the corresponding viscosity value; such that it will return 20 = xxx, 25 = xyxy.
I have 12 columns, in pair of temp and viscosity it is 6 columns (see attached file)
My function return the results correctly, but i need to put the results back into a matrix form so that i can write it into an excel sheet for further processing.
My code is:
function extract_viscosity
% This function extracts the viscosity at some designated temperature
% and return the temperature and average viscosity.
clc
filename = input('Enter an Excel file name: ','s');
[ri,header] = xlsread ([filename '.xls']);
% ask = input ('input file name', 's');
[~, col] = size(ri);
% mycell= repmat({NaN},size(ri));
% mycell= repmat({NaN},18);
% display (mycell);
A = [-0.05,-0.04,-0.03,-0.02,-0.01,0,0.01,0.02,0.03,0.04,0.05];
B = [20,25,30,35,40,45,50,55,60,65,70];
k=0;
for i = 1:1:11;
C = B(i) + A;
%display (C);
for t = 1:3:col;
col1 = ri(:,t);
col2 = ri(:,t+1);
solution = arrayfun(@(x) col2(find(col1== x,1,'first')),C','UniformOutput', false);
cmsolution = mean(cell2mat(solution));
stdeviation = std(cell2mat(solution));
% mymatrix(1:length(solution), t:t+1)= solution;
% cellconcat = cat(mycell', cmsolution);
display (mean(C'));
display (cmsolution);
display (stdeviation);
end
end
PLEASE SEE EXPECTED RESULT FORMAT IN THE SECOND SHEET (sheet name is result file) OF THE EXCEL FILE PROVIDED.
THANKS FOR ASSISTING!
Saheed.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by