clear all; clc;
%% parte dedicata a lettura dati
ncfile='T32TQM_20150704_20181230_S2_L3A_10m_TSM_CTWORCC_clip.nc';
ncinfo(ncfile);
ncdisp(ncfile);
x=ncread(ncfile,'x');
y=ncread(ncfile,'y');
% import time dimension
% convert date from days since 1970-01-01 to Matlab datetime
time= ncread(ncfile,'time');
date_matlab = datetime(time, 'convertfrom','posixtime');
figure
for t=131
startLoc = [1 1 t];
count = [Inf Inf 1];
d = ncread(ncfile,'TSM',startLoc,count);
d=d';
vmax(t)=max(max(d));
vmax= vmax'
B = rmmissing(d);
vmed=mean(mean(B));
[max_val,pos_idx]=max(d(:));
[rigas,clonax]=ind2sub(size(d),pos_idx);
[riga,colonna]=ind2sub(size(d),pos_idx);
vall=max(d(:))-10;
vall2=max(d(:))-15;
max=vall;
for i=1:length(d)
if max<vall && max>vall2
max=vall
end
end
% rob=log10(d);
[max_val2,pos_idx2]=find(d==max);
[rigas2,clonax2]=ind2sub(size(d),pos_idx2)
clf
mymap=pcolor(x,y,d);
mymap.EdgeAlpha=0
hold on
load coast
xx=x(riga)
yy=y(colonna)
xxx=x(4360);
yyy=y(3438);
xxxx=x(rigas2);
yyyy=y(clonax2);
plot(long,lat+0.1,'black')
scatter(xxx,yyy,'filled')
scatter(xxxx,yyyy,'filled')
scatter(xx,yy,'filled')
%contourf(x,y,d,7,'ShowText','on')
set(gca,'ColorScale','log')
caxis([1 10])
sr=colorbar
sr.Label.String = 'g/m^3';
xlabel('m');
ylabel('m')
caption = sprintf('%s','tsm [g/m3]' , date_matlab(t),'[UTC]',' V MAX_ ', vmax(t), ' v med_ ', vmed);
caption1 = sprintf('%s', date_matlab(t));
title(caption, 'FontSize', 10, 'FontWeight', 'bold', 'Color', 'b');
pause(2)
print(['TSM_01s' datestr(date_matlab(t),'ddmmyyyy') '.png'],'-dpng');
xx
yy;
foce=d(4360,3438);
PTOMAX=d(riga,colonna);
dist=(((xx-xxx)^2+(yy-yyy)^2)^(1/2))/1000
end
%%%%%%%%%%%%%QUESTION%%%%%%%%%%
Hi all, I have find the maximum value and plotted it as a point with SCATTER.
I would like to find all the points> 130 containing in the matrix d, find their x and y coordinates and plot them all together.

1 comentario

max=vall;
Don't do that! As soon as you do that, you cannot use max() as a function, which is something you do call upon!

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Dic. de 2020
mask = d > 130;
selected_d = d(mask);
selected_x = x(mask);
selected_y = y(mask);
pointsize = 20;
scatter(selected_x, selected_y, pointsize, selected_d); %color by d value

8 comentarios

DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 31 de Dic. de 2020
the response to the code is as follows:
also I create a logical d=5000x5000 matrix
The logical indices contain a true value outside of the array bounds.
Error in impdati01SATELLITARE_rev4 (line 54)
selected_x = x(mask);
DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 31 de Dic. de 2020
the matrix d contains NaN elements
[rigas3,clonax3] = find(d > 130);
xxxxxx = x(rigas3);
yyyyyy = y(clonax3);
scatter(xxxxxx, yyyyyy, 'filled')
DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 31 de Dic. de 2020
that's the answer, it doesn't work ....
xxxxxx =
0×1 empty double column vector
yyyyyy =
0×1 empty double column vector
You should be able to do
nanMask = isnan(d);
figure;
imshow(nanMask);
mask = d > 130;
mask(nanMask) = false;
figure
imshow(mask, []);
If you have trouble try again to remember to attach 'T32TQM_20150704_20181230_S2_L3A_10m_TSM_CTWORCC_clip.nc'
DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 2 de En. de 2021
hello thank you for the help.
with your advice I get a type 3 image(b&w), but I have to get a type 4 image (color).
I can't load the.nc file because it's too big.
practically, I have to see all points d> 130, save their coordinates and plot them on the color image of type 4
DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 2 de En. de 2021
DUMITRU ROBERT GUGIU
DUMITRU ROBERT GUGIU el 2 de En. de 2021
my code:
clear all; clc;
%% parte dedicata a lettura dati
ncfile='T32TQM_20150704_20181230_S2_L3A_10m_TSM_CTWORCC_clip.nc';
ncinfo(ncfile);
ncdisp(ncfile);
x=ncread(ncfile,'x');
y=ncread(ncfile,'y');
time= ncread(ncfile,'time');
date_matlab = datetime(time, 'convertfrom','posixtime');
figure
for t=233
startLoc = [1 1 t];
count = [Inf Inf 1];
d = ncread(ncfile,'TSM',startLoc,count);
d=d';
vmax(t)=max(max(d));
vmax= vmax'
B = rmmissing(d);
vmed=mean(mean(B));
[max_val,pos_idx]=max(d(:));
[riga,colonna]=ind2sub(size(d),pos_idx);
vall=max(d(:))-0.2;
vall2=max(d(:))-0.15;
max=vall;
% nanMask = isnan(d);
% imshow(nanMask);
% mask = d > 2;
% mask(nanMask) = false;
% figure
% imshow(mask, []);
clf
mymap=pcolor(x,y,d);
mymap.EdgeAlpha=0
hold on
load coast
xx=x(riga)
yy=y(colonna)
xxx=x(4360);
yyy=y(3438);
plot(long,lat+0.1,'black')
scatter(xxx,yyy,'filled')
% scatter(xxxx,yyyy,'filled')
scatter(xx,yy,'filled')
%contourf(x,y,d,7,'ShowText','on')
set(gca,'ColorScale','log')
caxis([1 5])
sr=colorbar
sr.Label.String = 'g/m^3';
xlabel('m');
ylabel('m')
caption = sprintf('%s','tsm [g/m3]' , date_matlab(t),'[UTC]',' V MAX_ ', vmax(t), ' v med_ ', vmed);
caption1 = sprintf('%s', date_matlab(t));
title(caption, 'FontSize', 10, 'FontWeight', 'bold', 'Color', 'b');
pause(2)
%print(['TSM_01s' datestr(date_matlab(t),'ddmmyyyy') '.png'],'-dpng');
% % % % %print(['imm_satellit_01S ' num2str(time(t)) '.png'],'-dpng');
xx
yy;
foce=d(4360,3438);
PTOMAX=d(riga,colonna);
dist=(((xx-xxx)^2+(yy-yyy)^2)^(1/2))/1000
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by