Create an array in workspace from multiple files
조회 수: 6 (최근 30일)
이전 댓글 표시
,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)')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/991220/image.jpeg)
댓글 수: 5
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?
답변 (1개)
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)
imagesc(kx, y.freq, y{:, 2:end});
colorbar
참고 항목
카테고리
Help Center 및 File Exchange에서 Red에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!