# Logical Test on Matrix Failing

4 views (last 30 days)
William Spriggs on 24 Apr 2017
Answered: Andrew Newell on 24 Apr 2017
I am having some difficulties with this function. For some reason the logical test:
little_endian_message(a) == 1
Doesn't work. Neither logical test works. But Matlab is able to return the correct element "little_endian_message(a)". Does anyone have any suggestions how I might fix this?
function [] = Generate_KC_Standard_Data( text_message )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
sample_rateHz = 44100;
f_low = 1200;
if true
% code
end
f_high = 2400;
w_low = (2*pi*f_low);
w_high = (2*pi*f_high);
low_sample_duration = (4/ f_low);
high_sample_duration = (8/ f_high);
low_sample_times = [0:(1/sample_rateHz):low_sample_duration];
high_sample_times = [0:(1/sample_rateHz):high_sample_duration];
low_tone = 120*sin(w_low*low_sample_times);
high_tone = 120*sin(w_high*high_sample_times);
sample_size = numel(low_tone);
binary_message = (dec2bin(text_message))';
(binary_message(:) - '0');
little_endian_message = flip( binary_message, 1 );
[row_size, column_size] = size(binary_message);
length = numel( little_endian_message );
sound_output = zeros( length, sample_size );
for a = 1:numel(little_endian_message)
if( little_endian_message(a) == 0 )
sound_output(a,:) = low_tone;
elseif(little_endian_message(a) == 1)
sound_output(a,:) = high_tone;
end
end
little_endian_message
numel(high_tone)
end

Andrew Newell on 24 Apr 2017
The variable little_endian_message is a char representation of binary numbers. Try this:
if( little_endian_message(a) == '0' )
sound_output(a,:) = low_tone;
elseif(little_endian_message(a) == '1')
sound_output(a,:) = high_tone;
end