i need a program in matlab..??

I have values like:
0-56 it should multiply with 92.5,
57-112 it should multiply with 95.2,
113-168 it should multiply with 95.8,
169-225 it should multiply with 95.9.
I need a program for these conditions. Please help me friends...

回答 (3 件)

Walter Roberson
Walter Roberson 2015 年 5 月 21 日

0 投票

histc with the two outputs to figure out which range you are in. Use the bin number to index a vector of constants to multiply.

5 件のコメント

nani kalyan
nani kalyan 2015 年 5 月 21 日
編集済み: nani kalyan 2015 年 5 月 21 日
i didnot understand your answer..??
Joseph Cheng
Joseph Cheng 2015 年 5 月 21 日
did you read the document of histc? the examples in the documentation can be adapted to:
test = 1:15;
binranges = [1 5 10 16];
[N bincounts] = histc(x,binranges)
output = zeros(size(x));
for ind = 1:length(binranges)-1
output(bincounts==ind) = x(bincounts==ind)*ind;
end
nani kalyan
nani kalyan 2015 年 5 月 21 日
what is 'x'......??
Joseph Cheng
Joseph Cheng 2015 年 5 月 21 日
x should be test. I was rushed but i'm sure you could have figured that out.
nani kalyan
nani kalyan 2015 年 5 月 21 日
no, i didnot get bro.
Andrei Bobrov
Andrei Bobrov 2015 年 5 月 21 日

0 投票

a = [92.5,95.2,95.8,95.9]';
x = randi(225,15,1);
[~,ii] = histc(x,[0,57,113,169,225]);
out = x.*a(ii);

2 件のコメント

nani kalyan
nani kalyan 2015 年 5 月 21 日
For the column 3, i need to check those conditions. so, i need the program for that.
Walter Roberson
Walter Roberson 2015 年 5 月 21 日
Use xlsread() to read column 3 of the file, and assign the values to x.
Image Analyst
Image Analyst 2015 年 5 月 21 日

0 投票

Here's another approach that does what (I think) you said :
% Make up some sample data
numElements = 100;
maxValue = 200; % Whatever
% Create sample data.
data = maxValue * rand(1, numElements);
% 0-56 it should multiply with 92.5,
% 57-112 it should multiply with 95.2,
% 113-168 it should multiply with 95.8,
% 169-225 it should multiply with 95.9.
% Do the algorithm.
% 0-56 it should multiply with 92.5,
logicalVector = data >= 0 & data < 56;
data(logicalVector) = data(logicalVector) * 92.5;
% 57-112 it should multiply with 95.2,
logicalVector = data >= 57 & data < 112;
data(logicalVector) = data(logicalVector) * 95.2;
% 113-168 it should multiply with 95.8,
logicalVector = data >= 113 & data < 168;
data(logicalVector) = data(logicalVector) * 95.8;
% 169-225 it should multiply with 95.9.
logicalVector = data >= 169 & data < 225;
data(logicalVector) = data(logicalVector) * 95.9;
Note that if your data is floating point, there are some gaps in your ranges, like values between 56 and 57 don't get multiplied by anything. However if you just have integers, that's not a problem

この質問は閉じられています。

タグ

タグが未入力です。

質問済み:

2015 年 5 月 21 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by