2-D colormap (loading .txt files)

8 views (last 30 days)
Chalisa Mawla
Chalisa Mawla on 3 May 2022
Commented: KSSV on 5 May 2022
I have the following code from my last assignment. The file names and types have been changed. The files like kx 0.txt and kx 10. txt have two lines of data like this
7.49481e+14 0.807996
7.39316e+14 0.798932
7.29422e+14 0.838482
7.1979e+14 0.868927
7.10409e+14 0.880881
I want to plot the first column of data as my y axis, and second column as my x axis, and to combine all files into a 2-D colot map like this (I will change this wavelength in the picture to frequency, and divide the numbers in the first column by 10^12,).
How I may change the lum.y0 into my first column of data and lum.x0 into my second column of data?
filenames={'kx 0.txt','kx 10.txt', 'kx 15.txt','kx 20.txt'} % here i have 50 .txt files like this
for i=1:numel(filenames)
t_data(:,i) = lum.y0
angle = linspace(0,0.5,51);
wav_leng = lum.x0.';
imagesc(angle,wav_leng,t_data); colormap turbo; axis xy;
ylabel('Freqency (THz)')
Chalisa Mawla
Chalisa Mawla on 4 May 2022
Hi Katherine,
let me double check on this. I dont think they are of different lengths. Maybe its just the end of the data is all zeros.

Sign in to comment.

Answers (1)

KSSV on 4 May 2022
thepath = 'kx values\*.txt' ;
files = dir(thepath) ;
N = length(files) ;
data = cell(N,1) ;
for i = 1:N
file = fullfile(files(i).folder,files(i).name) ;
data{i} = importdata(file) ;
data = cell2mat(data) ;
x = data(:,2) ;
y = data(:,1) ;
KSSV on 5 May 2022
It seems, the text file which you are reading has only one column. Check the text file, which shows this error.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by