Color Scale for looping script

5 ビュー (過去 30 日間)
Adi Purwandana
Adi Purwandana 2023 年 10 月 5 日
コメント済み: Dyuman Joshi 2023 年 10 月 5 日
Hello everyone,
I have some excel files. Each file containing some columns of parameter. I want to plot all of them in one graph with different color gradation (let's say jet colormap).
Below is my existing code from the begining but it failed to plot what I want (I don't know why, this code only plots one file/profile). Does Anyone know the lines I should modify?
best regards,
A=dir('*.xlsx'); %xls
for nn = 1:length(A)
filename = A(nn).name;
data = xlsread(filename); %
z = data(:,1); %first column
s = data(:,2);
t = data(:,3);
numprof = length(A); %number of profile
couleur = jet(numprof);
for nprf= 1:numprof
plot(s,t,'LineWidth',1,'color',couleur(nprf,:));
%legend of plot (?)
end
end
  5 件のコメント
Adi Purwandana
Adi Purwandana 2023 年 10 月 5 日
I want something like this.... this plot is using jet as the colormap. I don't think it should be scatter or surface to get.
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 5 日
Okay, you mean different colors for different plots. See my answer below.

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 5 日
There is no need of the 2nd for loop, remove it. I have taken random data for example to show a working code below.
Secondly, use readmatrix instead of the depreacted xlsread.
A=dir('*.xlsx'); %xls
%% Random value
numprof = 10; %length(A); %number of profile
couleur = jet(numprof);
%% Call a figure
figure
%% hold on to retain plots on the same figure
hold on
for nn = 1:numprof
%filename = A(nn).name;
%data = xlsread(filename); %
%z = data(:,1); %first column
%% Random data for example
s = rand(1,6);
t = rand(1,6);
plot(s,t,'LineWidth',1,'color',couleur(nn,:));
end
hold off
legend(compose("%d", 1:numprof))
  2 件のコメント
Adi Purwandana
Adi Purwandana 2023 年 10 月 5 日
It works fine. Thank you @Dyuman Joshi
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 5 日
You are welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by