matlab version problem

hai matlab expert.
i had a problem regarding version compatibility.
i ran the following program in matlab R2008a
clear;
clc;
a = imread('file.bmp'); %Reading Input File
b = bitand(a,240); %Extracting First 4 Bits from the MSB
c = bitand(a,15); %Extracting Last 4 Bits from the LSB
n = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
cntval = n;
disp('Size of the Image: ')
disp(size(a));
for i = 1:size(a,1)
for j = 1:size(a,2)
n(c(i,j)+1) = n(c(i,j)+1) + 1;
end
end
maxn = max(n);
disp('0\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\15');
disp(n);
disp('Total Value of the Pixels from 0 to 7');
disp(sum(n(:)));
for i = 1:16
if n(i) ~= maxn
n(i) = 0;
end
end
indn = find(n);
indn = indn - 1; %Index Stores the most frequently occuring value in the last 4 bits
disp('Maximum Value Index');
disp(indn);
newImg2 = b + uint8(indn); %New Image with last 4 bits with the most frequent value
difImg2 = uint8(abs(int16(a) - int16(newImg2)));
difImg2(difImg2(:)~=0) = 255;
%subplot(2,2,1)
%imshow(a);
%title('Original Image')
%subplot(2,2,2)
%imshow(b);
%title('First 5 Bits')
% subplot(2,2,3)
% imshow(newImg2);
% title('Maximum Value match')
% subplot(2,2,4)
% imshow(difImg2);
% title('Difference for Match')
% disp('Match in Mtc: ');
% disp(size(difImg2(:)) - size(find(difImg2)));
% disp('Error Percent of Accuracy in Mtc: ');
% disp((sum(abs(double(a(:)) - double(newImg2(:)))) / sum(a(:))) *
% double(100));
reqBinData = dec2bin(uint8(newImg2));
reqBinData1 = dec2bin(uint8(newImg2));
reqBinData = reqBinData';
singlArr = [reqBinData(4,:),reqBinData(3,:),reqBinData(2,:),reqBinData(1,:)];
dlmwrite('1.txt',singlArr, 'delimiter',' ','newline','pc');
reqMetrics = [size(a), indn]; %Metrics Required to Decode the file
disp(reqMetrics);
dlmwrite('metrics.txt',reqMetrics, 'delimiter',' ','newline','pc');
i does not have any error
but if run the same program in matlab R2009a
i am getting the following error for the same matlab program.
can any one say what is the reason and how to fix it?
??? operands to the || and && operators must be convertible to logical scalar values.
Error in ==> dec2bin at 31
if any(d<0) || any (~isfinite(d))
Error in --> sampic2 at 49
reqBinData = dec2bin(newImg2);
bye
[Merged information from duplicate Question]
dear sir
thanks for reply
i am very sorry sir, actually i tried to correct the program; that version i have posted.
the actual version is as follows:
----------------------------------------------------
clear;
clc;
a = imread(
'file.bmp'); %Reading Input File
b = bitand(a,240);
%Extracting First 4 Bits from the MSB
c = bitand(a,15);
%Extracting Last 3 Bits from the LSB
n = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
cntval = n;
disp(
'Size of the Image: ')
disp(size(a));
for
i = 1:size(a,1)
for j = 1:size(a,2)
n(c(i,j)+1) = n(c(i,j)+1) + 1;
end
end
maxn = max(n);
disp(
'0\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\15');
disp(n);
disp(
'Total Value of the Pixels from 0 to 7');
disp(sum(n(:)));
for
i = 1:16
if n(i) ~= maxn
n(i) = 0;
end
end
indn = find(n);
indn = indn - 1;
%Index Stores the most frequently occuring value in the last 3 bits
disp(
'Maximum Value Index');
disp(indn);
newImg2 = b + uint8(indn);
%New Image with last 3 bits with the most frequent value
difImg2 = uint8(abs(int16(a) - int16(newImg2)));
difImg2(difImg2(:)~=0) = 255;
%subplot(2,2,1)
%imshow(a);
%title('Original Image')
%subplot(2,2,2)
%imshow(b);
%title('First 5 Bits')
% subplot(2,2,3)
% imshow(newImg2);
% title('Maximum Value match')
% subplot(2,2,4)
% imshow(difImg2);
% title('Difference for Match')
% disp('Match in Mtc: ');
% disp(size(difImg2(:)) - size(find(difImg2)));
% disp('Error Percent of Accuracy in Mtc: ');
% disp((sum(abs(double(a(:)) - double(newImg2(:)))) / sum(a(:))) *
% double(100));
reqBinData = dec2bin(newImg2);
reqBinData = reqBinData';
singlArr = [reqBinData(4,:),reqBinData(3,:),reqBinData(2,:),reqBinData(1,:)];
dlmwrite(
'1.txt',singlArr, 'delimiter',' ','newline','pc');
reqMetrics = [size(a), indn];
%Metrics Required to Decode the file
disp(reqMetrics);
dlmwrite(
'metrics.txt',reqMetrics, 'delimiter',' ','newline','pc');
this is the following error i encountered when i execute in R2008a
??? Operands to the || and && operators must be convertible to logical scalar values.
Error in ==> dec2bin at 31
if any(d < 0) || any(~isfinite(d))
Error in ==> sampic2 at 49
reqBinData = dec2bin(newImg2);
i had highlighted the line showing error in red color.
what should i do in my code, such that it should work in R2009a without error.
sorrry for the inconsistent mail i send
your help will be appreciated for the response.
thank you sir

1 Comment

The line of code that you show as being in error does not occur in the source code you posted.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jun 2012

0 votes

dec2bin() is only documented as accepting a scalar value. It appears that in R2008a that it accepts arrays anyhow, but based on the error message it looks like in R2009a it only accepts vectors.
Unfortunately my connection to the bug report database is having difficulty so I cannot look to see if there is a report about this.

1 Comment

My answer remains the same: you are passing an array to dec2bin(), which has no defined result. Don't do that.
http://www.mathworks.com/support/bugreports/details.html?rp=557178

Sign in to comment.

Categories

Asked:

on 23 Jun 2012

Community Treasure Hunt

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

Start Hunting!