How to store values in workspace without using fprintf? but syntax should be quite similar to that of fprintf

조회 수: 2 (최근 30일)
a=[200 250 300];
b={};
% now I want this b should store values related to <200, 200-250, 250-300, >300, etc.
% like b should contain values which are <200, between 200 to 250 and so on
b{1,1}=[<200]
b{1,2}=[200-250]
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 11월 7일
Are you looking for the cells in b to store the elements extracted from a? Or are you looking for b to have strings like '<200' ?
Can sprintf() be used if fprintf() is not to be permitted?
KANCHAN PATIL
KANCHAN PATIL 2016년 11월 8일
Hello Walter, Thanks for the suggestion and I am looking for the cells in b to store the elements extracted from a. But I can't use any 'printf command. Can you help me with it?

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

답변 (2개)

Steven Lord
Steven Lord 2016년 11월 7일
Consider using the discretize function to determine the bin that contains each element in a.

Walter Roberson
Walter Roberson 2016년 11월 8일
[~, ~, bin] = histcounts(a, [-inf, 200, 250, 300, inf])
for k = 1:4
b{k} = a(bin==j) ;
end
no reason to get anywhere close to fprintf.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by