一种三合一组学数据可视化和分析方法附matlab代码

简介: 一种三合一组学数据可视化和分析方法附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信      无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机

⛄ 内容介绍

一种三合一组学数据可视化和分析方法附matlab代码

⛄ 完整代码

% For full user guidance, please see the first reference, and it is a free/open access (OA) article.

%

% References

% Zhao, H., & Wang, S. C. (2022). A Coding Basis and Three-in-One Integrated Data Visualization Method ‘Ana’ for the Rapid Analysis of Multidimensional Omics Dataset. In Life (Vol. 12, Issue 11, p. 1864). https://doi.org/10.3390/life12111864

% Zhao, H., Avena-Bustillos, R. J., & Wang, S. C. (2022). Extraction, Purification and In Vitro Antioxidant Activity Evaluation of Phenolic Compounds in California Olive Pomace. In Foods (Vol. 11, Issue 2). https://doi.org/10.3390/foods11020174

% matlab - How I obtain bars with function bar3 and different widths for each bar? - Stack Overflow. (n.d.). Retrieved September 3, 2022, from https://stackoverflow.com/questions/24269516/how-i-obtain-bars-with-function-bar3-and-different-widths-for-each-bar


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The percentage icon '%' means the contents after the % are all text notes instead of executable code.

clear, clc% clean RAM and command window

close all% close all figures, but Clustergram 1 must be closed manully.

tic % start timing

%%%%%%%%%%%%%%%%%%

% Initial input area for normal users or beginners


fn= 'olivephenolics';% input the excel file name in the '' area, olivephenolics can be replaced by user's excel file name, the excel file must be in the same folder as the this .m file

unt= 'mg/g';% input unit of data in the '' area, mg/g can be replaced by the user's unit, such as %, g/mL, mg/mL etc.

fs= 20;% input font size, 18-22 are recommended, must be >=7

cl= parula;% color style: jet(256) is rainbow; cool is blue to pink;  parula is blue to yellow; redbluecmap is blue to red; [] is transparent; user can replaced jet(256) by cool, [] or parula or bredbluecmap, etc.

pcamz= 10;% PCA marker size

pcalable= 0;% 0 will lable PCA vectors by variable/ compound numbers; 1 will lable PCA vectors by variable/ compound full names.

mk= '.'; % set PCA data marker in '' area; . is dot; p is star; s is square; * is snow flasker; o is o; 'd' is rhombus.


% Note: Method for print or output figures:


% Figure 1, 3D heatmap

% print(fig3Dbar,'olive-adjudtsize.png','-dpng','-r150');% -r150 defines 150dpi,-r300 will provide 300 dpi, -r100 will provide 100 dpi, etc. See S. Fig. 3


% Clustergram 1, heatmap cluster, can only be output to a pdf for high-resolution as descripted in S. Fig. 4.


% Figure 2-7, print PCA charts automatically at 150 dpi


%%%%%%%%%%%%%%%%%%%

% It may result in errors if modify code below this line if not skillful on MATLAB.

% But it would be greatly helpful for active learners to modify the code to improve coding skills.


fname= strcat(fn);% excel file name

info= readtable(fname,'PreserveVariableNames',true, 'ReadRowNames',true);% read data again for column names

rm= string(info.Properties.RowNames);% read row names of samples

cm= string(info.Properties.VariableNames);% read column/variable names of phenolic compounds

sz= size(info);% read data area size

ns= sz(1);% read sample number

nb= sz(2);% read compound number

num= readmatrix(fname); % read data only

num(:,1) = []; % delete first column NAN

ave= num; % define ave values

%


% plot 3D bar chart with size adjustments

%

fig3Dbar=figure; % name figure as fig3Dbar

h=bar3(ave,'detached');%'detached', 'grouped', or 'stacked'

%

values=ave; % values equal to ave.

m= 1.1*max(values(:))*2; % normalize constant for bar width, 1.1 ensure a small distance between bars

shading interp % set color shading properties

for i = 1:length(h)% the following code set bottom size in accordance with the z-axis values

   % Get the ZData matrix of the current group

   xdata= get(h(i),'Xdata');

   ydata= get(h(i),'Ydata');

   zdata= get(h(i),'Zdata');

   set(h(i),'Cdata',zdata)

   for k = 1:size(xdata,1)/6

       datax = xdata((k-1)*6+1+(0:5),:);

       datay = ydata((k-1)*6+1+(0:5),:);

       dirx=((datax-round(datax))>0)-((datax-round(datax))<0);

       diry=((datay-round(datay))>0)-((datay-round(datay))<0);

       xdata((k-1)*6+1+(0:5),:) = round(xdata((k-1)*6+1+(0:5),:),0)+dirx*values(ceil(((k-1)*6+1)/6),i)/m;

       ydata((k-1)*6+1+(0:5),:) = round(ydata((k-1)*6+1+(0:5),:),0)+diry*values(ceil(((k-1)*6+1)/6),i)/m;

   end

   set(h(i),'XData',xdata);

   set(h(i),'YData',ydata);

end

%set(h,'EdgeColor','k') % set edge color as k black

view(-25, 83); % default view angle

colormap (cl) % set colormap as cl

colorbar % show color bar

%

xticks(1:nb)% add x ticks

yticks(1:ns)% add y ticks

set(gca,'XTickLabel',cm)% label x axis by column/variable names of phenolic compound

set(gca,'YTickLabel',rm)% label y axis by row names of samples

set(h,'FaceAlpha',.8) % set transparency of bars to 0.5

zlabel(unt,'FontSize',fs) % set font size of z-axis

ax = gca;

ax.FontSize = fs; % set font size of color code bar

cb=colorbar;

colormap(cl); % define color as descripted by cl

cb.Label.String = unt; % set unit of color code bar as descripted by unt

%print(fig3Dbar,'olive-adjudtsize.png','-dpng','-r150');% -r150 defines 150dpi,-r300 will provide 300 dpi, -r100 will provide 100 dpi, etc.


% Cluster analysis

cfac=clustergram(ave, 'RowLabels', rm,'ColumnLabels',cm,'Colormap',colormap(cl),'Standardize','Row'); % the code standardize data on each row

% For more information see: https://www.mathworks.com/help/bioinfo/ref/clustergram.html

set(cfac,'Linkage','complete','Dendrogram',10)

set(cfac,'Annotate','off') % turn of annotate

set(cfac,'Linkage','Average') % set linkage method by Average

set(cfac,'RowPDist','Euclidean') % row distance method Euclidean

set(cfac,'ColumnPDist','Euclidean') % column distance method Euclidean

%

% PCA

sdz = zscore(ave,[],2); % standardized data along data rows

[coefs,score,latent,tsquared,explainedvariance] = pca(sdz); % run PCA

%

if pcalable== 0 % 0 will lable PCA vectors by variable/ compound numbers; 1 will lable PCA vectors by variable/ compound full names.

   lbls= string(1:length(cm));

else

   lbls= cm;

end

%

figPCA12biplot= figure; % open a new figure

pa12= biplot(coefs(:,1:2),'Scores',score(:,1:2),'VarLabels',lbls,'Marker',mk,'MarkerSize',pcamz); % plot PCA biplot of PC1 vs. PC2

grid off % turn off grid

box off % ture off box

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel(['PC1',' ', num2str(explainedvariance(1)),'%'],'FontSize',fs)% label x-axis

ylabel(['PC2',' ', num2str(explainedvariance(2)),'%'],'FontSize',fs)% label y-axis

print(figPCA12biplot,'PCA12-biplot.png','-dpng','-r150');% print figure at 150 dpi

%

clr = hsv(ns);

figPCA12score= figure;

gscatter(score(:,1),score(:,2),rm,clr,mk) % plot PCA scoreplot of PC1 vs. PC2

legend('Location','northeastoutside')

grid off % turn off grid

box off % ture off box

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel(['PC1',' ', num2str(explainedvariance(1)),'%'],'FontSize',fs)% label x-axis

ylabel(['PC2',' ', num2str(explainedvariance(2)),'%'],'FontSize',fs)% label y-axis

print(figPCA12score,'PCA12-score.png','-dpng','-r150');% print figure at 150 dpi

%

figPCA23biplot= figure; % open a new figure

pa23= biplot(coefs(:,2:3),'Scores',score(:,2:3),'VarLabels',lbls,'Marker',mk,'MarkerSize',pcamz); % plot PCA biplot of PC2 vs. PC3

grid off % turn off grid

box off % ture off box

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel(['PC2',' ', num2str(explainedvariance(2)),'%'],'FontSize',fs)

ylabel(['PC3',' ', num2str(explainedvariance(3)),'%'],'FontSize',fs)

print(figPCA23biplot,'PCA23-biplot.png','-dpng','-r150');

%

figPCA12score= figure;

gscatter(score(:,2),score(:,3),rm,clr,mk)% plot PCA scoreplot of PC2 vs. PC3

legend('Location','northeastoutside')

grid off % turn off grid

box off % ture off box

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel(['PC2',' ', num2str(explainedvariance(2)),'%'],'FontSize',fs)% label x-axis

ylabel(['PC3',' ', num2str(explainedvariance(3)),'%'],'FontSize',fs)% label y-axis

print(figPCA12score,'PCA23-score.png','-dpng','-r150');% print figure at 150 dpi

%

figPCA123biplot= figure; % open a new figure

pa123= biplot(coefs(:,1:3),'Scores',score(:,1:3),'VarLabels',lbls,'Marker',mk,'MarkerSize',pcamz); % plot PCA biplot of PC1 vs. PC2 vs. PC3

grid off % turn off the grid

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel(['PC1',' ', num2str(explainedvariance(1)),'%'],'FontSize',fs)

ylabel(['PC2',' ', num2str(explainedvariance(2)),'%'],'FontSize',fs)

zlabel(['PC3',' ', num2str(explainedvariance(3)),'%'],'FontSize',fs)% label z-axis

box on % ture on box

print(figPCA123biplot,'PCA123-biplot.png','-dpng','-r150');

%

ev= figure;

pareto(explainedvariance,0.99) % draw Explained Variance

ax = gca;

ax.FontSize = fs-6; % set font size of tick, 6 less than label font size

xlabel('Principal Component','FontSize',fs)

ylabel('Explained Variance(%)','FontSize',fs)

box off % ture off box

print(ev,'PCA-Explained-Variance.png','-dpng','-r150');

toc% stop timing

⛄ 运行结果

⛄ 参考文献

[1]宋驰等. "一种文本数据挖掘与可视化的新方法." 北京生物医学工程 27.2(2008):5

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料


相关文章
|
15天前
|
算法 Serverless
基于魏格纳函数和焦散线方法的自加速光束matlab模拟与仿真
本项目基于魏格纳函数和焦散线方法,使用MATLAB 2022A模拟自加速光束。通过魏格纳函数法生成多种自加速光束,并设计相应方法,展示仿真结果。核心程序包括相位和幅度的计算、光场分布及拟合分析,实现对光束传播特性的精确控制。应用领域涵盖光学成像、光操控和光束聚焦等。 关键步骤: 1. 利用魏格纳函数计算光场分布。 2. 模拟并展示自加速光束的相位和幅度图像。 3. 通过拟合分析,验证光束加速特性。 该算法原理基于魏格纳函数描述光场分布,结合数值模拟技术,实现对光束形状和传播特性的精确控制。通过调整光束相位分布,可改变其传播特性,如聚焦或加速。
|
19天前
|
算法 人机交互 数据安全/隐私保护
基于图像形态学处理和凸包分析法的指尖检测matlab仿真
本项目基于Matlab2022a实现手势识别中的指尖检测算法。测试样本展示无水印运行效果,完整代码含中文注释及操作视频。算法通过图像形态学处理和凸包检测(如Graham扫描法)来确定指尖位置,但对背景复杂度敏感,需调整参数PARA1和PARA2以优化不同手型的检测精度。
空心电抗器的matlab建模与性能仿真分析
空心电抗器是一种无铁芯的电感元件,通过多层并联导线绕制而成。其主要作用是限制电流、滤波、吸收谐波和提高功率因数。电抗器的损耗包括涡流损耗、电阻损耗和环流损耗。涡流损耗由交变磁场引起,电阻损耗与电抗器半径有关,环流损耗与各层电流相关。系统仿真使用MATLAB2022a进行。
|
27天前
|
编解码 算法 数据安全/隐私保护
基于BP译码的LDPC误码率matlab仿真,分析不同码长,码率,迭代次数以及信道类型对译码性能的影响
本内容介绍基于MATLAB 2022a的低密度奇偶校验码(LDPC)仿真,展示了完整的无水印仿真结果。LDPC是一种逼近香农限的信道编码技术,广泛应用于现代通信系统。BP译码算法通过Tanner图上的消息传递实现高效译码。仿真程序涵盖了不同Eb/N0下的误码率计算,并分析了码长、码率、迭代次数和信道类型对译码性能的影响。核心代码实现了LDPC编码、BPSK调制、高斯信道传输及BP译码过程,最终绘制误码率曲线并保存数据。 字符数:239
74 5
|
1月前
|
算法 数据安全/隐私保护
数字通信中不同信道类型对通信系统性能影响matlab仿真分析,对比AWGN,BEC,BSC以及多径信道
本项目展示了数字通信系统中几种典型信道模型(AWGN、BEC、BSC及多径信道)的算法实现与分析。使用Matlab2022a开发,提供无水印运行效果预览图、部分核心代码及完整版带中文注释的源码和操作视频。通过数学公式深入解析各信道特性及其对系统性能的影响。
|
3月前
|
编解码 算法 数据安全/隐私保护
基于BP译码的LDPC误码率matlab仿真,分析码长,码率,信道对译码性能的影响,对比卷积码,turbo码以及BCH码
本程序系统基于BP译码的LDPC误码率MATLAB仿真,分析不同码长、码率、信道对译码性能的影响,并与卷积码、Turbo码及BCH编译码进行对比。升级版增加了更多码长、码率和信道的测试,展示了LDPC码的优越性能。LDPC码由Gallager在1963年提出,具有低复杂度、可并行译码等优点,近年来成为信道编码研究的热点。程序在MATLAB 2022a上运行,仿真结果无水印。
67 0
|
4月前
|
算法 数据可视化
基于SSA奇异谱分析算法的时间序列趋势线提取matlab仿真
奇异谱分析(SSA)是一种基于奇异值分解(SVD)和轨迹矩阵的非线性、非参数时间序列分析方法,适用于提取趋势、周期性和噪声成分。本项目使用MATLAB 2022a版本实现从强干扰序列中提取趋势线,并通过可视化展示了原时间序列与提取的趋势分量。代码实现了滑动窗口下的奇异值分解和分组重构,适用于非线性和非平稳时间序列分析。此方法在气候变化、金融市场和生物医学信号处理等领域有广泛应用。
283 19
|
5月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
259 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
5月前
|
算法 Perl
【光波电子学】基于MATLAB的多模光纤模场分布的仿真分析
本文介绍了基于MATLAB的多模光纤模场分布仿真分析,详细阐述了多模光纤的概念、实现方法、仿真技术,并利用模式耦合方程分析方法,通过理论和仿真模型设计,展示了不同模式下的光场分布及其受光纤参数影响的分析结果。
256 4
【光波电子学】基于MATLAB的多模光纤模场分布的仿真分析
|
4月前
|
算法 数据挖掘 vr&ar
基于ESTAR指数平滑转换自回归模型的CPI数据统计分析matlab仿真
该程序基于ESTAR指数平滑转换自回归模型,对CPI数据进行统计分析与MATLAB仿真,主要利用M-ESTAR模型计算WNL值、P值、Q值及12阶ARCH值。ESTAR模型结合指数平滑与状态转换自回归,适用于处理经济数据中的非线性趋势变化。在MATLAB 2022a版本中运行并通过ADF检验验证模型的平稳性,适用于复杂的高阶自回归模型。