Plotting variables of continuously array with different colors

조회 수: 1 (최근 30일)
Adi Purwandana
Adi Purwandana 2023년 10월 10일
편집: Adi Purwandana 2023년 10월 11일
Hello everyone,
Is it possible to :
(1) Change the value of Station column of this array (excel attached) into ordered rank Station? Anyone knows the code to do this? FYI, the number of stations is in hundreds (I put here for example only 3 stations) so, doing this in loop is preferable solution.
(2) Plot those three Station's profile of variable "s" vs depth from those three stations with different colors of line plots? Anyone knows the code to do this also?
Thank you!

채택된 답변

Star Strider
Star Strider 2023년 10월 10일
편집: Star Strider 2023년 10월 10일
You can use either unique or findgroups for this to get serial indices —
T1 = readtable('datax.xlsx')
T1 = 17×5 table
Station lon lat depth salinity _______ ______ _____ _____ ________ 2 114.64 -8.16 0 33.995 2 114.64 -8.16 2 33.994 2 114.64 -8.16 4 33.994 2 114.64 -8.16 6 33.993 2 114.64 -8.16 8 33.993 2 114.64 -8.16 10 33.992 7 114.72 -8.16 0 33.976 7 114.72 -8.16 2 33.978 7 114.72 -8.16 4 33.977 7 114.72 -8.16 6 33.977 31 114.8 -8.16 0 33.983 31 114.8 -8.16 2 33.981 31 114.8 -8.16 4 33.981 31 114.8 -8.16 6 33.981 31 114.8 -8.16 8 33.981 31 114.8 -8.16 10 33.98
[Us,ix1,ix2] = unique(T1.Station, 'stable');
T1.Station = ix2
T1 = 17×5 table
Station lon lat depth salinity _______ ______ _____ _____ ________ 1 114.64 -8.16 0 33.995 1 114.64 -8.16 2 33.994 1 114.64 -8.16 4 33.994 1 114.64 -8.16 6 33.993 1 114.64 -8.16 8 33.993 1 114.64 -8.16 10 33.992 2 114.72 -8.16 0 33.976 2 114.72 -8.16 2 33.978 2 114.72 -8.16 4 33.977 2 114.72 -8.16 6 33.977 3 114.8 -8.16 0 33.983 3 114.8 -8.16 2 33.981 3 114.8 -8.16 4 33.981 3 114.8 -8.16 6 33.981 3 114.8 -8.16 8 33.981 3 114.8 -8.16 10 33.98
figure
stem3(T1.Station, T1.depth, T1.salinity, ':k', 'Marker','none')
hold on
scatter3(T1.Station, T1.depth, T1.salinity, 150, T1.salinity, 'p', 'filled')
hold off
xlabel('Station')
ylabel('Depth')
zlabel('Salinity')
xticks(1:3)
This uses the third output of unique to get serial indices (note that I use the 'stable' argument to avoid sorting the results). The findgroups function works similarly to produce a grouping variable. The grouping variable vector is used here as the new value for ‘Station’.
EDIT — Added plots.
.
  댓글 수: 12
Adi Purwandana
Adi Purwandana 2023년 10월 11일
편집: Adi Purwandana 2023년 10월 11일
I think I solved it...
LON(k,:) = StaData{k}.long(1);
Star Strider
Star Strider 2023년 10월 11일
That is correct.
Actually:
LON = StaData{k}.lon(1);
or:
LON(k) = StaData{k}.lon(1);
depending on the result you want.
(I was away for a few minutes running errands.)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 10월 10일
Logical indexing would be an easy way of sorting the data and assigning new values to column 'station'. Then use the sorted data indecies to plot the data: s vs. depth
Here is one of the ways of doing it:
F = readmatrix('datax.xlsx');
Idx1=F(:,1)==2;
Idx2=F(:,1)==7;
Idx3=F(:,1)==31;
F(Idx1,1) = 1;
F(Idx2,1) = 2;
F(Idx3,1) = 3;
% Plotting the data
plot(F(Idx1, 5),F(Idx1, 4), '-o','linewidth', 2), hold all
plot(F(Idx2, 5),F(Idx2, 4), '-s','linewidth', 2)
plot(F(Idx3, 5),F(Idx3, 4), '-d','linewidth', 2)
legend('Station: 1', 'Station: 2', 'Station: 3', 'location', 'best')
grid on
xlabel('s')
ylabel('depth')
  댓글 수: 1
Adi Purwandana
Adi Purwandana 2023년 10월 10일
Thank you @Sulaymon Eshkabilov. It's solved if the number of station is not much. In my case, the number of stations is in hundreds and even thousands. Do you know to do that in something like looping lines to do this?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by