Reading numeric values from csv file
Afficher commentaires plus anciens
Hi there. I am trying to read numeric values on matlab from a csv file that is created using PuTTY. I want to read data in realtime from row 5 going onwards and column 3 specifically. The data is being captured in realtime. I have tried a using a matlab code but I can't seem to read in the numeric values. I also want to store the values displayed into an array for later use. Please kindly assist
5 commentaires
Jan
le 7 Juin 2022
Please post code as text, not as screenshot. Then it is much easier to re-use it in an answer.
"I can't seem to read" is not a useful explanation of what you observe. We cannot reproduce your setup, so it would be useful to tell us, what happens.
How does PuTTY create CSV files? Is the file still opened by PuTTY? Then you cannot access the contents usually.
Jan
le 7 Juin 2022
[MOVED from section for answers] Lola wrote:
I apologise for the lack of information. PuTTY is open while running MATLAB code. I am trying to observe data in realtime from a sensor connected to arduino board. Through serial communication PuTTY displays values observed from the sensor. Basically PuTTY is replacing the Arduino IDE serial monitor.
Below is the code I used in MATLAB:
for i = 1:10000
filename = 'orange.csv';
x = csvread(filename,5,2)
pause(1);
end
The errors matlab shows are:
Error using dlmread
Number of HeaderColumns is greater than number of columns in file
Jan
le 7 Juin 2022
@Lola: Usually Matlab is used to read the serial data directly, such that the indirections over PuTTY and a file are not necessary.
The start of the file looks strange:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2022.06.07 18:39:20 =~=~=~=~=~=~=~=~=~=~=~=
IR= 627 BPM= 0 Avg BPM= 0
626 BPM= 0 Avg BPM= 0
IR= 626 BPM= 0 Avg BPM= 0
0 Avg BPM= 0
IR= 623 BPM= 0 Avg BPM= 0
IR= 623 BPM= 0 Avg BPM= 0
IR= 626 BPM= 0 Avg BPM= 0
IR= 626 BPM= 0 Avg BPM= 0
IR= 630 BPM= 0 Avg BPM= 0
csvread requires a file with a strict layout.
Lola
le 8 Juin 2022
Walter Roberson
le 8 Juin 2022
csvread can skip text header lines, and it can skip a fixed number of columns that can include text. But all entries after that on the line must be purely numeric. The only values that csvread would be able to handle in that file are the BPM (all of which happen to be 0 in the sample)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!