フィルターのクリア

Scatter Color Scale for Looping Script

1 回表示 (過去 30 日間)
Adi Purwandana
Adi Purwandana 2023 年 10 月 6 日
コメント済み: Dyuman Joshi 2023 年 10 月 6 日
Dear 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 (let's say jet colormap).
Here is my code:
A = dir('*.xlsx');
numprof = length(A); %number of profile
couleur = jet(numprof);
hold on;
for nn = 1:numprof
filename = A(nn).name;
data = xlsread(filename); %
a = data(:,1);
b = data(:,2);
% Plot
scatter(lon(1),lat(1),'filled','color',couleur(nn,:)); % plot the first row value from each excel file
end
legend(compose("% d", 1:numprof),'Location','eastoutside');
This code produce this:
The scatter colors did not following jet colormap. Does anyone know the line I should add in this script?
best regards,
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 6 日
The behaviour/functionality of scatter() is different than plot().
To clarify, you are trying to plot the first pair of points from each file?
Adi Purwandana
Adi Purwandana 2023 年 10 月 6 日
Each file contains two columns. Let's start the loop for the 1st file... I want to plot the first row from both columns (from the 1st file off course), and let's say, this will be plotted as scatter blue (from the spectrum of jet). Then, move to the second file, I do the same and will be plotted as scatter as green... and so on... the last file will be plotted as red.

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

採用された回答

Matthew Blomquist
Matthew Blomquist 2023 年 10 月 6 日
編集済み: Matthew Blomquist 2023 年 10 月 6 日
One option would be to store those values into an array within the for loop, and then plot the arrays with a colormap of jet after going through the loop. Something like:
A = dir('*.xlsx');
numprof = length(A); %number of profile
figure() ;
hold on;
% Initialize
lon = zeros( numprof , 1 ) ;
lat = zeros( numprof , 1 ) ;
for nn = 1:numprof
filename = A(nn).name;
data = xlsread(filename); %
lon(nn,1) = data(1,1);
lat(nn,1) = data(1,2);
end
% For colorbar
c = 1 : numprof ;
% Plot
scatter(lon,lat,[],c,'filled');
colorbar
colormap jet
  3 件のコメント
Adi Purwandana
Adi Purwandana 2023 年 10 月 6 日
Thank you very much @Matthew Blomquist and @Dyuman Joshi. It works fine.
Here is my final codes:
clear all;
clc;
A = dir('*.xlsx');
A = natsortfiles(A);
numprof = length(A); %number of profile
hold on;
% Initialize
lon = zeros( numprof,1);
lat = zeros( numprof,1);
for nn = 1:numprof
filename = A(nn).name;
data = readmatrix(filename); %
lon(nn,1) = data(1,1);
lat(nn,1) = data(1,2);
end
% For colorbar
c = 1:numprof ;
% Plot
scatter(lon,lat,[],c,'filled');
colorbar
colormap jet
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 6 日
Looks good.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by