치춘짱베리굿나이스
200810 Matlab csv -> RGB scatter graph 본문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
csvlist = dir('C:\Users\jiyoo\Documents\code\binfiles\*/*.csv'); | |
N = size(csvlist, 1); | |
arrX = []; | |
arrY = []; | |
arrZ = []; | |
arrC = []; | |
for i = 1 : N | |
filename = [csvlist(i).name]; | |
cd(csvlist(i).folder); | |
filemat = readmatrix(filename); | |
%indexing matrix for individual graph | |
X = filemat(1:end, 10); | |
Y = filemat(1:end, 11); | |
Z = filemat(1:end, 12); | |
C = filemat(1:end, 10:12) / 255; | |
%concatenate matrix for all-in-one graph | |
arrX = vertcat(arrX, X); | |
arrY = vertcat(arrY, Y); | |
arrZ = vertcat(arrZ, Z); | |
temp = size(X); | |
temp1 = []; | |
for i = 1 : 3 | |
temp1 = horzcat(repmat(rand(), temp(1), 1), repmat(rand(), temp(1), 1), repmat(rand(), temp(1), 1)); | |
end | |
arrC = vertcat(arrC, temp1); | |
%print individual graph | |
scatter3(X, Y, Z, 25, C, '*'); | |
axis([0 255 0 255 0 255]); | |
title(strcat(filename, ' RGB scatter')); | |
xlabel('R'); | |
ylabel('G'); | |
zlabel('B'); | |
saveas(gcf, strcat(strcat('00', filename), '.png')); | |
end | |
%print all-in-one graph with randomly generated color plot | |
%arrC = horzcat(arrX, arrY, arrZ) / 255; | |
scatter3(arrX, arrY, arrZ, 25, arrC, '*'); | |
axis([0 255 0 255 0 255]); | |
title('RGB scatter'); | |
xlabel('R'); | |
ylabel('G'); | |
zlabel('B'); | |
saveas(gcf, '0000graph.png'); |
교수님이 자료 3축그래프로 정리하라하셔서 일괄작성용으로 쓴 매트랩코드
폴더 (지금 내 작업폴더 csv파일있는곳으로 경로지정됨) 내에 모든 csv파일 읽어서 그래프에 plot하고 png로 일괄저장함
그래프 폴더를 따로 만들어서 거기다가 저장할까? 하다가 걍 귀찮고 일부러 정리되게 파일명에 00 붙여놔서
좀 지저분해보이는 거 빼고 지장은없음


이런식으로
해당 점의 R G B값에따라 색도 그걸로 지정해줌

근데 한꺼번에 표시할땐 저렇게하면 색 비슷해보이는 애들끼리 겹쳐보여서
랜덤으로 색 generate하게 해서 작업함
매트랩도 잘만 쓰면 matplotlib보다 그래프 더 예쁘게 그릴수있을거같은데
그렇게 쓸일이 없는거같음 우리과에선
'기타공부 > 기타의 기타' 카테고리의 다른 글
[백준] 2377 (0) | 2023.07.05 |
---|---|
[백준] 2372 (0) | 2023.07.05 |
M1 맥에 가상환경 설치하기 (Ubuntu) + ssh 설정 (0) | 2022.07.19 |
VSCode 자주쓰는 단축키 정리 (0) | 2021.03.17 |
200805 VSCode 자주쓰는 명령어 정리 (0) | 2021.02.09 |
Comments