How do I keep my current group IDs but then add in two other variables that the code needs to consider?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a code below that seperates the items in an excel sheet into groups based on their lithology. I have attached it below along with the excel sheet. However, I am now needing to not only group by lithology but also to be able to read off each lithology's void ratio and bulk density. These two extra variables are also in the excel sheet, just in a different column. Is there any way to do this? Any help would be appriciated.
t = readtable('CostaRica_1253.xlsx');
[G,group_ID] = findgroups(t{:,4});
n_groups = numel(group_ID);
new_t = cell(1,n_groups);
for ii = 1:n_groups
new_t{ii} = t(G == ii,:);
end
Chalk1_1253=new_t{1};
%%
Gabbro_1253=new_t{2};
%%
Chalk2_1253=new_t{3};
%%
Chalk_1253=[Chalk1_1253;Chalk2_1253];
%%
Siliciclastic_1253=[Chalk_1253;Gabbro_1253];
Siliciclastic_1253_data = [table2array(Siliciclastic_1253(:,2)) table2array(Siliciclastic_1253(:,5:8))];
%%
figure(4)
plot(Siliciclastic_1253_data(:,3),Siliciclastic_1253_data(:,1),'b.');
axis ij
xlabel ('Porosity(%)');
ylabel ('Depth(m)');
title('Costa Rica 1253 Porosity Vs Depth');
hold on
0 Commenti
Risposta accettata
Voss
il 30 Dic 2022
Modificato: Voss
il 30 Dic 2022
t = readtable('CostaRica_1253.xlsx','VariableNamingRule','preserve');
[G,group_ID] = findgroups(t{:,4});
n_groups = numel(group_ID);
new_t = cell(1,n_groups);
for ii = 1:n_groups
new_t{ii} = t(G == ii,:);
end
% rather than hard-coding indices (e.g., Chalk_1253=[new_t{1};new_t{3}]),
% it's better to use the group_ID, in case you ever want to run this code
% on another input file where the groups are in a different order.
% Chalk_1253 = vertcat(new_t{strcmpi(group_ID,'chalk')});
% in this case, Siliciclastic_1253 includes all 3 groups, but I assume this
% input file is only part of the actual larger input file which has more
% groups (but if you really want to use all groups, you could just use the
% original table "t" instead of defining "Siliciclastic_1253" at all)
Siliciclastic_1253 = vertcat(new_t{ismember(lower(group_ID),{'chalk' 'gabbro'})});
% rather than using table2array(), you can construct a matrix from columns
% of the table like this:
% Siliciclastic_1253_data = [Siliciclastic_1253{:,[2 5:8]}];
% but you probably don't need that, since you can plot (or whatever) from
% the table directly:
figure
subplot(1,3,1)
plot(Siliciclastic_1253{:,6},Siliciclastic_1253{:,2},'b.');
axis ij
xlabel ('Porosity');
ylabel ('Depth(m)');
subplot(1,3,2)
plot(Siliciclastic_1253{:,7},Siliciclastic_1253{:,2},'b.');
axis ij
xlabel ('Void Ratio');
title('Costa Rica 1253');
subplot(1,3,3)
plot(Siliciclastic_1253{:,5},Siliciclastic_1253{:,2},'b.');
axis ij
xlabel ('Bulk Density(g/cm^3)');
% However, it seems likely that you want the plots to depict the different
% groups, and that the "Chalk" and "chalk" groups should be treated as one
% (so you can use lower(t{:,4}) in findgroups)
[G,group_ID] = findgroups(lower(t{:,4}));
n_groups = numel(group_ID);
new_t = cell(1,n_groups);
for ii = 1:n_groups
new_t{ii} = t(G == ii,:);
end
% create figure
figure
% pick some colors (make sure you have enough - one for each group):
colors = get(gca(),'ColorOrder');
% then plot the data for each group separately (or use gscatter)
for ii = 1:n_groups
subplot(1,3,1)
plot(new_t{ii}{:,6},new_t{ii}{:,2},'Color',colors(ii,:),'Marker','.','LineStyle','none');
hold on
subplot(1,3,2)
plot(new_t{ii}{:,7},new_t{ii}{:,2},'Color',colors(ii,:),'Marker','.','LineStyle','none');
hold on
subplot(1,3,3)
plot(new_t{ii}{:,5},new_t{ii}{:,2},'Color',colors(ii,:),'Marker','.','LineStyle','none');
hold on
end
subplot(1,3,1)
axis ij
xlabel ('Porosity');
ylabel ('Depth(m)');
subplot(1,3,2)
axis ij
xlabel ('Void Ratio');
title('Costa Rica 1253');
subplot(1,3,3)
axis ij
xlabel ('Bulk Density(g/cm^3)');
group_ID_for_legend = group_ID;
for ii = 1:n_groups
group_ID_for_legend{ii}(1) = upper(group_ID_for_legend{ii}(1));
end
legend(group_ID_for_legend,'Location','Best')
2 Commenti
Voss
il 31 Dic 2022
You're welcome!
I would start by taking the code I posted in my answer that generates the second plot, and use it as-is with your other data file.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Geographic Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!