필터 지우기
필터 지우기

How to take ascii file and plot into scatter plot?

조회 수: 5 (최근 30일)
nines
nines 2021년 11월 8일
편집: Dave B 2021년 11월 8일
Hello!
I have an ascii file that looks like this (called lh_text):
bankssts 4.2726
caudalanteriorcingulate 5.2143
caudalmiddlefrontal 2.8891
cuneus 2.4075
entorhinal 2.4987
fusiform 3.5651
inferiorparietal 3.1224
I tried to load it into matlab using the following command:
lh_SNR=load('lh_text', '-ascii')
But am getting the error: ' unknown text of line one of ASCII file '
I would like to make a bar plot that has the values as the y axis, and the names of the structures (e.g. bankssts, fusiform) as the labels on the x axis (please see attached!)
Can you help me convert this file to a file that I can plot?

채택된 답변

Dave B
Dave B 2021년 11월 8일
편집: Dave B 2021년 11월 8일
readtable will do well to read in the file
converting it to categorical will make it easier to make a bar out of
reordercats will help for changing the order on the x axis (I did them by the height of the bars, but you could do them by whatever order you like)
figure(1)
t=readtable('lh_text.txt');
t.Var1=categorical(t.Var1);
bar(t.Var1, t.Var2)
% if you want it in order of biggest to smallest bar:
figure(2)
[~,sortind] = sort(t.Var2,'descend');
t.Var1=reordercats(t.Var1,sortind);
bar(t.Var1, t.Var2)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by