MATLAB Practice questions solution

211 views (last 30 days)
Ali Awada
Ali Awada on 3 Jan 2021
Answered: Abhiram Rayidi on 27 Jun 2022
Hello all,
I am new to MATLAB and I am still trying to learn it by myself. I was trying to solve the questions posted by MATLAB. I know I didn't use the double function as suggested so please enlighten me with your ideas and let me know if i was at least close to what the problem is asking for:
The provided text file (readings.txt) contains a timestamp broken up into year, month, day, hour, minute, second, and timezone components, as well as a reading from a sensor. Write a script that reads the data from the file using the textscan function.
The script must:
  • Convert the timestamps into single numeric serial date numbers stored in a variable named dates
  • Ignore the timezone component of the timestamp by not reading it into the workspace
  • Place numeric values for the readings in a single array of type double with a variable name of readings
clear all
fileID1 = fopen('readings.txt');
dates = textscan(fileID1, '%s %s %s %s %s %s %s %s');
whos dates;
C=textscan(fileID2, '%q %q %q %q %q %q %*q %q');
whos C;
D=textscan(fileID3,'%*q %*q %*q %*q %*q %*q %*q %q');
whos D;

Answers (3)

Image Analyst
Image Analyst on 3 Jan 2021
Perhaps datenum()?
>> d=datenum(now)
d =
Ali Awada
Ali Awada on 11 Jan 2021
the problem asks us to use the function textscan

Sign in to comment.

Kazem Gheysari
Kazem Gheysari on 24 Aug 2021
Edited: Kazem Gheysari on 24 Aug 2021
fileID = fopen('readings.txt');
C_text = textscan(fileID,'%s',8,'Delimiter',' ');
C = textscan(fileID,'%f %f %f %f %f %f EST %f','Delimiter',' ','EmptyValue',-Inf);
Y = C{1,1};
M = C{1,2};
D = C{1,3};
H = C{1,4};
MN= C{1,5};
S = C{1,6};
dates = datenum(Y,M,D,H,MN,S)
readings = C{1,7};
  1 Comment
Image Analyst
Image Analyst on 24 Aug 2021
What is (I did not click your link because there is no explanation)

Sign in to comment.

Abhiram Rayidi
Abhiram Rayidi on 27 Jun 2022
syms y(t);
dsolve(diff(y)==y, y(0)==1, 'Expansion Point', 0)


Find more on Dates and Time 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!

Translated by