Create an array in workspace from multiple files
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
,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 Kommentare
KSSV
am 9 Mai 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?
Antworten (1)
Chunru
am 9 Mai 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
Siehe auch
Kategorien
Mehr zu Red finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!