From char to double for plotting
이전 댓글 표시
Hello,
I have n=12 "double" data set called I_n. I want a subplot (histogram in this case), for each data set. With the following code the function histogram doesn't recognize the "char" value. How can I better implement this?
figure()
for n=1:12
chartname = strcat('I_',num2str(n));
subplot(3,4,n)
histogram(chartname)
hold on
end
채택된 답변
추가 답변 (1개)
Image Analyst
2022년 6월 18일
Do this klunky way:
subplot(3,4,1)
histogram(I_1)
subplot(3,4,2)
histogram(I_2)
subplot(3,4,3)
histogram(I_3)
subplot(3,4,4)
histogram(I_4)
subplot(3,4,5)
histogram(I_5)
subplot(3,4,6)
histogram(I_6)
subplot(3,4,7)
histogram(I_7)
subplot(3,4,8)
histogram(I_8)
subplot(3,4,9)
histogram(I_9)
subplot(3,4,10)
histogram(I_10)
subplot(3,4,11)
histogram(I_11)
subplot(3,4,12)
histogram(I_12)
Now you know why it's not good to have so many uniquely-named variables. You should put them all into a matrix, like @Bjorn Gustavsson suggested, if you can. Then you could use a simple, compact for loop like you wanted.
See the FAQ:
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!