Logical Test on Matrix Failing

조회 수: 1 (최근 30일)
William Spriggs
William Spriggs 2017년 4월 24일
답변: Andrew Newell 2017년 4월 24일
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

답변 (1개)

Andrew Newell
Andrew Newell 2017년 4월 24일
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

카테고리

Help CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by