MATLAB Practice questions solution

조회 수: 115 (최근 30일)
Ali Awada
Ali Awada 2021년 1월 3일
댓글: DEEPAK RAJ B 2024년 1월 20일
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
clc
clear all
fileID1 = fopen('readings.txt');
dates = textscan(fileID1, '%s %s %s %s %s %s %s %s');
fclose(fileID1);
whos dates;
celldisp(dates)
fileID2=fopen('readings.txt')
C=textscan(fileID2, '%q %q %q %q %q %q %*q %q');
fclose(fileID2);
whos C;
celldisp(C)
fileID3=fopen('readings.txt');
D=textscan(fileID3,'%*q %*q %*q %*q %*q %*q %*q %q');
fclose(fileID3);
whos D;
celldisp(D)
  댓글 수: 1
DEEPAK RAJ B
DEEPAK RAJ B 2024년 1월 20일
add one section to the end of the script

댓글을 달려면 로그인하십시오.

답변 (3개)

Image Analyst
Image Analyst 2021년 1월 3일
Perhaps datenum()?
>> d=datenum(now)
d =
738159.473416505
  댓글 수: 7
Image Analyst
Image Analyst 2021년 1월 10일
Then just use the first 3 lines and skip the rest of the lines that have to do with plotting.
Ali Awada
Ali Awada 2021년 1월 11일
the problem asks us to use the function textscan

댓글을 달려면 로그인하십시오.


Kazem Gheysari
Kazem Gheysari 2021년 8월 24일
편집: Kazem Gheysari 2021년 8월 24일
clear
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);
fclose(fileID);
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
Image Analyst
Image Analyst 2021년 8월 24일
What is matlab1.com? (I did not click your link because there is no explanation)

댓글을 달려면 로그인하십시오.


Abhiram Rayidi
Abhiram Rayidi 2022년 6월 27일
syms y(t);
dsolve(diff(y)==y, y(0)==1, 'Expansion Point', 0)
Error using symengine
Unexpected 'identifier'.

Error in mupadengine/evalin_internal

Error in dsolve>mupadDsolve (line 333)
sys = [sys_sym reshape(evalin_internal(symengine, sys_str), 1, [])];

Error in dsolve (line 203)
sol = mupadDsolve(args, options);
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 6월 16일
syms y(t);
dsolve(diff(y)==y, y(0)==1, 'ExpansionPoint', 0)
ans = 

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Platform and License에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by