How do I concatenate the data to plot multiple spectra in one graph

4 ビュー (過去 30 日間)
Amanda Figueroa
Amanda Figueroa 2018 年 5 月 31 日
コメント済み: Amanda Figueroa 2018 年 6 月 1 日
So I have been trying to import 167 .csv files from a directory. These files should be plotted together (j vs w) and I would like to concatenate all the j (dims 2204x1) values as a matrix. The first column should be w (dims 2204x1), which is constant for all the files and the rest should be the 167 'j' values. So far I've been successful at reading all these files, but I cannot build a matrix (I also can't plot these). I chose the row values "15:end" because there is no data prior to this.
I've been combing through the forums and I can't seem to find the right code to do this. I've tried using brackets and curly brackets.
Any help would be appreciated!
a=dir('*.csv');
for i=1:length(cell(size(a)))
bob = sprintf('_ (%i).csv',i)
[~,~,idx{i}]=xlsread(bob);
w=table(idx(:,1));
j=table(idx(:,2));
w=w{15:end,'Var1'};
j=j{15:end,'Var1'};
end

採用された回答

Walter Roberson
Walter Roberson 2018 年 5 月 31 日
a = dir('*.csv');
numfiles = length(a);
for i = 1 : numfiles
bob = sprintf('_ (%i).csv',i)
[~,~,idx]=xlsread(bob);
if i == 1
w = idx(15:end,1));
j = zeros(size(w,1), numfiles);
end
j(:,i) = idx(15:end,2);
end
  1 件のコメント
Amanda Figueroa
Amanda Figueroa 2018 年 6 月 1 日
Thanks Walter,
I ended up modifying this code since xlsread did not read the data I wanted. I really appreciate your help
a = dir('*.csv');
numfiles = length(a);
for i = 1 : numfiles
bob = sprintf('_ (%i).csv',i)
data(i)=importdata(bob)
plot(data(i).data(:,1),data(i).data(:,2))
hold on
if i==1
w = data(i).data(1:end,1);
j = data(i).data(1:end,2);
end
j(:,i) = data(i).data(1:end,2);
end
hold off
xlabel('Wavenumber (cm^-^1)')
ylabel('Reflectance')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by