Create an array in workspace from multiple files
2 views (last 30 days)
Show older comments
,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 Comments
KSSV
on 9 May 2022
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?
Answers (1)
Chunru
on 9 May 2022
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
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!