I want to interface with the DHT11 sensor in matlab.But program give this error Subscripted assignment dimension mismatch. Error in Untitled (line 27) Humi(i)=str2num(out(5:9)); Can you help me?
Show older comments
clc
clear all
delete(instrfindall);
close(instrfindall);
s = serial('COM3');
time=100;
i=1;
while(i<time)
fopen(s)
fprintf(s, 'Your serial data goes here')
out = fscanf(s)
Temp(i)=str2num(out(1:4));
subplot(211);
plot(Temp,'g');
axis([0,time,20,50]);
title('Parameter: DHT11 Temperature');
xlabel('---> time in x*0.02 sec');
ylabel('---> Temperature');
grid
Humi(i)=str2num(out(5:9));
subplot(212);
plot(Humi,'m');
axis([0,time,25,100]);
title('Parameter: DHT11 Humidity');
xlabel('---> time in x*0.02 sec');
ylabel('---> % of Humidity ');
grid
fclose(s)
i=i+1;
drawnow;
end
delete(s)
clear s
5 Comments
Geoff Hayes
on 28 Apr 2020
Erhan - why 5:9 in
Humi(i)=str2num(out(5:9));
? Perhaps out isn't exactly what you think it is. I recommend using the MATLAB debugger to check to see what out is and what out(5:9) becomes. It could be two numbers (separated by a space?) that creates an array of two or more elements via str2num.
Erhan erhnbgdtl
on 28 Apr 2020
Geoff Hayes
on 28 Apr 2020
What is the out variable set to? Either use the MATLAB debugger to determine the value or print it out with
out = fscanf(s)
fprintf('out is set to : %s\n', out);
Erhan erhnbgdtl
on 28 Apr 2020
Erhan erhnbgdtl
on 28 Apr 2020
Accepted Answer
More Answers (2)
Erhan erhnbgdtl
on 28 Apr 2020
0 votes
Erhan erhnbgdtl
on 28 Apr 2020
0 votes
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

