I have a problem in the annexed excel file there are two tables, first table give the graph representing geological layers I need to get the second table with Matlab Code
1 次查看(过去 30 天)
显示 更早的评论
I have a problem in the annexed excel file there are two tables, first table give the graph representing geological layers I need to get the second table with suitable Matlab code (I have R2014b version).
3 个评论
回答(3 个)
Star Strider
2023-3-6
编辑:Star Strider
2023-3-6
One approach —
C1 = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1315950/Salt%20Dome%20Interpretation.xlsx')
nidx = find(cell2mat(cellfun(@ismissing,C1(5,:), 'Unif',0)));
Partition1 = cell2table(C1(2:end,1:nidx(1)-1), 'VariableNames',C1(1,1:nidx(1)-1))
Partition2 = cell2table(C1(2:end,nidx(2)+1:size(C1,2)), 'VariableNames',C1(1,1:nidx(1)-1))
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1315950/Salt%20Dome%20Interpretation.xlsx')
file = websave('Salt%20Dome%20Interpretation','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1315950/Salt%20Dome%20Interpretation.xlsx')
[Data,Text] = xlsread(file);
Data
Text = Text(1,:)
nidx = find(ismissing(Text))
Data1 = Data(:,1:nidx(1)-1)
Data2 = Data(:,nidx(2)+1:numel(Text))
% Matrix1 = table2array(Partition1)
% writematrix()
.
5 个评论
Star Strider
2023-3-6
It is straightforward to separate these two matrices using matrix indexing, as I have demonstrated, using ismissing to determine where one sub-matrix ends and the other begins.
My code should be robust to similar Excel files that have the same general structure.
Star Strider
2023-3-7
@Moustafa Abedel Fattah — With respect to your edited Comment, I already provided both tables. I call them ‘Data1’ and ‘Data2’ however you cal call them whatever you want. My code should also work in R2014b, since it uses xlsread for compatibility.
Sulaymon Eshkabilov
2023-3-6
Here is the solution. readmatrix() is option 1 and xlsread() is option 2:
D = readmatrix('Salt Dome Interpretation.xlsx');
% D = xlsread('Salt Dome Interpretation.xlsx');
D(1:2,:) = []; % NaNs removed
D(:,11:12) = []; % NaNs removed
%%
D1 = D(:,3:10);
D2 = D(:, 13:20);
figure
plot(D(:,1), D1)
grid on
set(gca, 'YDir','reverse')
legend('z1', 'z2', 'z3', 'z4', 'z5', 'z6', 'z7')
figure
plot(D(:,11), D2)
grid on
set(gca, 'YDir','reverse')
legend('z1', 'z2', 'z3', 'z4', 'z5', 'z6', 'z7')
6 个评论
Sulaymon Eshkabilov
2023-3-6
If understood your explanations, here is how to collect the data from table to w.r.t xc range values and constant values of z1 .. to zb by computing their difference:
D = readmatrix('Salt Dome Interpretation.xlsx');
D(1:2,:) = []; % NaNs removed
D(:,11:12) = []; % NaNs removed
%
D1 = D(:,1:10);
D1(200:end,:)=[]; % NaNs removed
D2 = D(:, 11:20);
D2(200:end,:)=[]; % NaNs removed
figure(1)
plot(D1(:,1), D1(:,3:10))
grid on
set(gca, 'YDir','reverse')
legend({'z_1', 'z_2', 'z_3', 'z_4', 'z_5', 'z_6', 'z_7', 'z_b'}, 'Location','NE', 'NumColumns',2)
ylabel('z_1, z_2, ... z_b')
xlabel('x_c')
xc = D2(:,1);
INDEX =xc>=228.47935834853 & xc<= 320.84335427666;
DD2 = D2(INDEX,:);
% Find constant values of z1 ... zb using diff()
Dz1 = diff(DD2(:,3)); ind_z1 = Dz1==0;
Dz2 = diff(DD2(:,4)); ind_z2 = Dz2==0;
Dz3 = diff(DD2(:,5)); ind_z3 = Dz3==0;
Dz4 = diff(DD2(:,6)); ind_z4 = Dz4==0;
Dz5 = diff(DD2(:,7)); ind_z5 = Dz5==0;
Dz6 = diff(DD2(:,8)); ind_z6 = Dz6==0;
Dz7 = diff(DD2(:,9)); ind_z7 = Dz7==0;
Dzb = diff(DD2(:,10)); ind_zb = Dzb==0;
% Take out those values
z1=DD2(ind_z1,3);
z2=DD2(ind_z2,4);
z3=DD2(ind_z3,5);
z4=DD2(ind_z4,6);
z5=DD2(ind_z5,7);
z6=DD2(ind_z6,8);
z7=DD2(ind_z7,9);
zb=DD2(ind_zb,10);
% Take out the corresponding xc values for plateaued values of z1 to zb
xc1 = DD2(ind_z1,1);
xc2 = DD2(ind_z2,1);
xc3 = DD2(ind_z3,1);
xc4 = DD2(ind_z4,1);
xc5 = DD2(ind_z5,1);
xc6 = DD2(ind_z6,1);
xc7 = DD2(ind_z7,1);
xcb = DD2(ind_zb,1);
figure(2)
plot(xc1,z1, 'r*-'),
hold on
plot(xc2,z2, 'bd-')
plot(xc3,z3, 'gh--')
plot(xc4,z4, 'mp-.')
plot(xc5,z5, 'kd-')
plot(xc6,z6, 'm^--')
plot(xc7,z7, 'k>-.')
plot(xcb,zb, 'b-', 'linewidth', 2), grid on
grid on
ylabel('z_1, z_2, ... z_b')
xlabel('x_c')
set(gca, 'YDir','reverse')
legend({'z_1', 'z_2', 'z_3', 'z_4', 'z_5', 'z_6', 'z_7', 'z_b'}, 'Location','NE', 'NumColumns',2)
hold off
% The same figure as in Figure (2) but better scaled yy axis
figure(3)
yyaxis left
plot(xc1,z1, 'r*-'),
hold on
plot(xc2,z2, 'bd-')
plot(xc3,z3, 'gh--')
plot(xc4,z4, 'mp-.')
plot(xc5,z5, 'kd-')
plot(xc6,z6, 'm^--')
plot(xc7,z7, 'k>-.')
set(gca, 'YDir','reverse')
yyaxis right
plot(xcb,zb, 'b-', 'linewidth', 2), grid on
grid on
set(gca, 'YDir','reverse')
YC=gca;
YC.YColor='b';
legend({'z_1', 'z_2', 'z_3', 'z_4', 'z_5', 'z_6', 'z_7', 'z_b'}, 'Location','NE', 'NumColumns',2)
ylabel('z_b')
xlabel('x_c')
hold off
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!