Display char matrix vertically

조회 수: 9 (최근 30일)
Mohit Garg
Mohit Garg 2019년 10월 18일
답변: Andrei Bobrov 2019년 10월 18일
이 질문에 Andrei Bobrov 님이 플래그를 지정함
I have 2 matrixes, one numeric (volt) and one char (c)
a=find(volt>=0 & volt<=10);
p=find(volt>10 & volt<=20);
g=find(volt>20 & volt<=30);
o=find(volt>30 & volt<=40);
u=find(volt>40 | volt<0);
c=zeros(1,length(volt));
c(a)='A';
c(p)='P';
c(g)='G';
c(o)='O';
c(u)='U';
volt = [18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36];
How do I display the two matrices identical to the following:
18.0 P
33.0 O
31.0 O
34.0 O
15.0 P
37.0 O
10.5 P
48.0 U
50.0 U
38.0 O
...
  댓글 수: 2
Daniel M
Daniel M 2019년 10월 18일
편집: Daniel M 2019년 10월 18일
Display where - the workspace, written to a file?
Mohit Garg
Mohit Garg 2019년 10월 18일
Just print it in the command window using fprintf or disp

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 10월 18일
volt = [18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36];
edges = -40:10:0;
[~,~,j] = histcounts(-volt,edges);
ss = flip({'u','a','p','g','o','u'}');
sj = ss(j+1);
for i1 = 1:numel(volt)
fprintf('%6.1f %s\n',volt(i1),sj{i1});
end

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by