I want to plot in a different barcolors
Show older comments
Dear All,
I have this code and when I run it it shows both set of data in jet colorbar while I want to distinguish these two from eachother? Would you please advice me what to do?
Best,
Ara
% Initialize video writer for combined visualization
video_filename = 'ROTI_S4_Map_Visualization_MovingCircles_4.avi';
video_writer = VideoWriter(video_filename, 'Motion JPEG AVI');
video_writer.FrameRate = 30;
open(video_writer);
% Define the date range for filtering
start_date = datetime(2023, 4, 23, 0, 0, 0);
end_date = datetime(2023, 4, 23, 23, 59, 59);
% Initialize figure and map
figure('Position', [100, 100, 1200, 800]);
latlim = [35 70];
lonlim = [-10 40];
% Pre-read S4 data for all stations
station_data = struct();
for station_num = 1:29
filename_s4 = sprintf('Station%d.xlsx', station_num);
try
data_s4 = readmatrix(filename_s4, 'OutputType', 'string');
station_data(station_num).data = data_s4;
catch
disp(['File ', filename_s4, ' not found. Skipping.']);
end
end
% Loop over each 5-minute interval
fileDates = {'20230423'};
for d = 1:length(fileDates)
date_str = fileDates{d};
time_bins = start_date:minutes(5):end_date;
for t = 1:length(time_bins)-1
% Clear current frame
cla;
% Re-draw the base map
ax = worldmap(latlim, lonlim);
setm(ax, 'FFaceColor', [0.5 0.7 0.9]);
load coastlines;
geoshow(coastlat, coastlon, 'DisplayType', 'polygon', 'FaceColor', [0.6 0.8 0.6]);
geoshow('landareas.shp', 'FaceColor', [0.8 0.8 0.8]);
hold on;
% Define current time window
current_time = time_bins(t);
hour_str = datestr(current_time, 'HH');
minute_str = datestr(current_time, 'MM');
filename_vtec = sprintf('C:\\Users\\I7-2600K\\Desktop\\data\\%s_%s%s00_roti.dat', ...
date_str, hour_str, minute_str);
if isfile(filename_vtec)
data_ROTI = readmatrix(filename_vtec);
if size(data_ROTI, 2) >= 3
lon_ROTI = data_ROTI(:, 1);
lat_ROTI = data_ROTI(:, 2);
ROTI = data_ROTI(:, 3);
scatterm(lat_ROTI, lon_ROTI, 30, ROTI, 'filled');
colormap(ax, jet);
colorbar;
caxis([0 0.5]);
cb_roti = colorbar('southoutside');
cb_roti.Label.String = 'ROTI';
title(['ROTI Map - ', datestr(current_time)]);
end
else
disp(['ROTI file not found: ', filename_vtec]);
end
% Plot S4 as moving circles
for station_num = 1:29
if isfield(station_data(station_num), 'data')
data_s4 = station_data(station_num).data;
time_str_s4 = data_s4(:, 1);
S4 = str2double(data_s4(:, 3));
Lon_IPP = str2double(data_s4(:, 15));
Lat_IPP = str2double(data_s4(:, 16));
elevation = str2double(data_s4(:, 5));
time_dt_s4 = datetime(time_str_s4, 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.SSS');
% Filter for current time interval and elevation > 30 deg
valid_idx = (time_dt_s4 >= time_bins(t)) & ...
(time_dt_s4 < time_bins(t+1)) & ...
(elevation >= 30);
if any(valid_idx)
S4_filtered = S4(valid_idx);
Lon_IPP_filtered = Lon_IPP(valid_idx);
Lat_IPP_filtered = Lat_IPP(valid_idx);
for i = 1:length(S4_filtered)
color = [0 1 0]; % Green for low scintillation
if S4_filtered(i) > 0.05
color = [1 0 0]; % Red for high scintillation
end
scatterm(Lat_IPP_filtered(i), Lon_IPP_filtered(i), ...
100, color, 'o', 'filled', ...
'MarkerEdgeColor', 'k', 'LineWidth', 0.5);
end
end
end
end
colormap(ax, parula); % Can be changed
caxis([0 0.3]);
cb_s4 = colorbar('eastoutside');
cb_s4.Label.String = 'S4';
drawnow;
frame = getframe(gcf);
writeVideo(video_writer, frame);
end
end
close(video_writer);
disp(['Video saved to ', video_filename]);
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!