2D plot using data from different text files
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 11 text files with two columns - one is wavelength and other is transmittance. Each file is for a particular angle of incidence. Now I need to plot a 2d plot with color bar depicting variations in transmittance with wavelength along one axis and angle of incidence along another axis. What code should I use ?
댓글 수: 2
Dyuman Joshi
2024년 1월 25일
Do you have problem importing the files and subsequently the data? In that case, check - https://in.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html
Otherwise, specify what you are having trouble with.
답변 (1개)
George Abrahams
2024년 1월 25일
Something along these lines? (Pun intended)
fileNames = [ "a.txt", "b.txt", "c.txt", "d.txt", "e.txt" ];
angleOfIncidence = [ 0, 20, 40, 60, 80 ]; % in the same order as fileNames.
n = numel( fileNames );
ax = axes( "NextPlot", "add", "ColorOrder", turbo( n ), "Box", "on" );
for iFileName = 1 : n
% Read the text files.
fileData = readmatrix( fileNames(iFileName) );
% Plot the wavelength-transmittance line.
plot( ax, fileData(:,1), fileData(:,2), "LineWidth", 2 )
end
xlabel( ax, "Wavelength [nm]" )
ylabel( ax, "Transmittance [%]" )
lgd = legend( ax, string( angleOfIncidence ) + "°", ...
"Location", "eastoutside" );
title( lgd, "Angle of Incidence" )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1600256/image.png)
From a quick Google, this seems to be the typical format for graphs of this type.
I don't think this is what you requested, but I can't figure out exactly what you mean by "a color bar depicting variations in transmittance with wavelength along one axis and angle of incidence along another axis".
댓글 수: 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!