Create an array in workspace from multiple files

조회 수: 5 (최근 30일)
Chalisa Mawla
Chalisa Mawla 2022년 5월 8일
댓글: Chalisa Mawla 2022년 5월 9일
,filenames={'kx 10.txt','kx 20.txt','kx 30.txt'}
for i=1:numel(filenames)
load(filenames{i});
%print(filenames{i});
t_data(:,i) = lum.y0
end
Each file contains two columns of data, the first column is the range of frequency (same for every file) and the second column is the corresponding data (transmission). How can I create a block in the workspace to compile all the transmission data? (lum.x0 and lum.y0 is from the previous code. lum.y0 compiles all transmission data)
I wanted to make a colormap to represent different transmission data over the same range of frequency for all kx values (from file 0 to file 500). How can I proceed from here? Thank you.
%making the plot
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
KSSV
KSSV 2022년 5월 9일
Your question is not quiet clear. You have two data points from the text files and third one you are defining on your own. How to link the third one with the existing data?
Chalisa Mawla
Chalisa Mawla 2022년 5월 9일
Sorry for the confusion. The third one is the kx value, the kx0.txt means those data is recorded for kx=0, kx10.txt records data at kx=0.1 etc.

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

답변 (1개)

Chunru
Chunru 2022년 5월 9일
unzip("kx values.zip");
filenames = dir('*.txt');
filenames = sort({filenames.name}');
nfiles = length(filenames);
nfiles = 36; % other files have different rows of data; check it out
kx = zeros(nfiles, 1);
for i=1:nfiles
x = readtable(filenames{i});
np = size(x, 1);
var = strrep(filenames{i}, " ", "");
var = strrep(var, ".txt", "");
kx(i) = sscanf(var, 'kx%d');
x.Properties.VariableNames = ["freq", var];
if i == 1
y = x;
else
y = [y x(:, end)];
end
end
head(y)
ans = 8×37 table
freq kx0 kx10 kx20 kx30 kx40 kx50 kx60 kx70 kx80 kx90 kx100 kx110 kx120 kx130 kx140 kx150 kx160 kx170 kx180 kx190 kx200 kx210 kx220 kx230 kx240 kx250 kx260 kx270 kx280 kx290 kx300 kx310 kx320 kx330 kx340 kx350 __________ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ 7.4948e+14 0.80895 0.81085 0.80982 0.81134 0.81316 0.81595 0.81877 0.82081 0.8224 0.82157 0.8205 0.81796 0.8158 0.81291 0.81076 0.80748 0.80416 0.79888 0.79337 0.7879 0.78405 0.78337 0.78387 0.79341 0.81287 0.808 0.77626 0.76049 0.75479 0.75756 0.80729 0.77293 0.74945 0.73787 0.72801 0.72061 7.3932e+14 0.83253 0.83291 0.83239 0.83491 0.83691 0.83848 0.83906 0.838 0.83753 0.83585 0.83547 0.83486 0.83508 0.83422 0.83444 0.83505 0.83793 0.84582 0.86047 0.85047 0.82543 0.81747 0.81014 0.80544 0.80195 0.79893 0.793 0.79366 0.79107 0.78894 0.78922 0.7916 0.81214 0.82683 0.80019 0.7815 7.2942e+14 0.85617 0.85378 0.85581 0.85713 0.85853 0.85861 0.85814 0.85767 0.8577 0.8603 0.86445 0.8728 0.88519 0.8855 0.87121 0.86268 0.85671 0.85471 0.8533 0.85278 0.85228 0.84881 0.84687 0.84294 0.84148 0.83848 0.83534 0.83541 0.83444 0.83078 0.82761 0.82495 0.82485 0.82665 0.84273 0.87904 7.1979e+14 0.86695 0.86962 0.86848 0.86725 0.86741 0.87264 0.88943 0.90643 0.90445 0.8985 0.89368 0.88923 0.88632 0.88515 0.88534 0.88499 0.88565 0.88438 0.88293 0.88012 0.87748 0.87647 0.87507 0.87426 0.87163 0.86893 0.86943 0.862 0.85686 0.85641 0.85466 0.85531 0.85487 0.85592 0.85454 0.85297 7.1041e+14 0.94431 0.93542 0.92305 0.91414 0.90993 0.90624 0.90389 0.90101 0.89939 0.89954 0.89978 0.90121 0.90213 0.90217 0.90057 0.89949 0.8973 0.89608 0.89546 0.89481 0.89416 0.89149 0.88839 0.88592 0.88405 0.88088 0.87605 0.8769 0.87692 0.87123 0.8669 0.86043 0.85422 0.84904 0.8227 0.74535 7.0127e+14 0.93387 0.93628 0.93634 0.93693 0.93423 0.91555 0.88366 0.87773 0.88566 0.89067 0.89462 0.89658 0.89811 0.89804 0.89899 0.89908 0.89891 0.89842 0.89624 0.89434 0.89239 0.89001 0.88784 0.8846 0.87838 0.87806 0.87148 0.86901 0.86429 0.85842 0.85151 0.7767 0.56929 0.7346 0.81674 0.83319 6.9236e+14 0.92983 0.9316 0.93186 0.93025 0.92916 0.92979 0.93131 0.93397 0.93518 0.93126 0.90865 0.85871 0.84857 0.86221 0.87319 0.87883 0.88201 0.88348 0.88232 0.881 0.87861 0.87564 0.8759 0.87118 0.86434 0.86209 0.86092 0.83754 0.68444 0.78146 0.83535 0.84891 0.85767 0.86369 0.86471 0.85948 6.8368e+14 0.93019 0.92935 0.93032 0.92929 0.92851 0.92756 0.92619 0.92553 0.92371 0.92264 0.92197 0.92107 0.91919 0.91682 0.90824 0.8746 0.81041 0.81498 0.83476 0.84729 0.85109 0.85012 0.85551 0.84812 0.82568 0.71962 0.84859 0.85971 0.84971 0.84192 0.83024 0.82502 0.8283 0.84975 0.67779 0.78826
imagesc(kx, y.freq, y{:, 2:end});
colorbar
  댓글 수: 1
Chalisa Mawla
Chalisa Mawla 2022년 5월 9일
Epic! This looks exactly like the band structure that my prof asked me to do.

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

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by