2-D colormap (loading .txt files)

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)
load(filenames{i});
%print(filenames{i});
t_data(:,i) = lum.y0
end
angle = linspace(0,0.5,51);
wav_leng = lum.x0.';
figure;
imagesc(angle,wav_leng,t_data); colormap turbo; axis xy;
xlabel('kx')
ylabel('Freqency (THz)')

댓글 수: 5

DGM
DGM 2022년 5월 3일
It's not clear how the files are to be assembled (whether they have the same length and whether the first columns match)
It would be easier if you just zip the files (or a sample of files) and attach it.
Otherwise, if they're all the same size and correspond to the same Y vector, then you should be able to take all the second columns and insert them into a Mx50 array as you work through the loop.
Chalisa Mawla
Chalisa Mawla 2022년 5월 3일
Hi DGM,
All those kx 0. txt/kx 10.txt and such (I have 51 of them) are of same length. the first columns are matching because the data is recorded for the same frequency. I will attach all of them.
Chalisa Mawla
Chalisa Mawla 2022년 5월 3일
Could you please check the attached files? Unfortunately I dont know how to insert them into a Mx50 array..the previous code did it with the lum.y0 and lum.x0
Katherine Zheng
Katherine Zheng 2022년 5월 3일
Hi Chalisa, your datais quite interesting.From 0-36, the data length is 402 and from 37 onwards, it becomes 201. I am not sure what you are looking for, to extract all the txt file into one matrix?
Chalisa Mawla
Chalisa Mawla 2022년 5월 4일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2022년 5월 4일

0 개 추천

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) ;
end
data = cell2mat(data) ;
x = data(:,2) ;
y = data(:,1) ;

댓글 수: 4

Chalisa Mawla
Chalisa Mawla 2022년 5월 4일
>> matrix
Index in position 2 exceeds array bounds.
Error in matrix (line 10)
x = data(:,2) ;
I was getting this error. What does this mean?
KSSV
KSSV 2022년 5월 4일
I have not received any error while running the code. For which file you got the error?
Chalisa Mawla
Chalisa Mawla 2022년 5월 4일
It doesnt say
It only says Index in position 2 exceed array bounds.
KSSV
KSSV 2022년 5월 5일
It seems, the text file which you are reading has only one column. Check the text file, which shows this error.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Orange에 대해 자세히 알아보기

제품

질문:

2022년 5월 3일

댓글:

2022년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by