Question

Hi, i am working with MATLAB. I have a text file from which I have to...

Hi, i am working with MATLAB. I have a text file from which I have to read in my data. So far i have this in my code.

fid = fopen('ecgnormaloff.txt', 'r');

data = textscan(fid,'%f')

According to all the websites, this should be enough to read in my points, however, I get this as my output

data =

1×1 cell array

{0×1 double}

>>

And when I try to access my data, there is nothing. I do not want to actually attach my text file, since this is homework, and will further be used in a project. so I will simply try to show you what the text file looks like. I hope the next chunk is helpful to visualize it (It is data points for an ecg trace).

Lead Number 1 Time Step .02 Data Points 6001

number

number

number

....

(there are all floating point numbers!)

(theres 6001 data points, therefore the numbers continue onto column 6002 because of the header.)

>>

>>

Thanks in advance!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution for your problem is provided below, please comment if any doubts:

There is nothing wrong with your code but the format you try to print is not correct to display the read data. It is because the “textscan()” function read the data into a cell array. The cell array will not display just by removing the semi colon after the “textscan()” function. You have to use “celldisp(data)” to display the contents you read into the data variable. The normal printing will print only the size of the cell array.

Thus if you need to display the cell array data you read to data variable, it needed to add an extra command “celldisp(data)” as given below:

fid = fopen('ecgnormaloff.txt', 'r');

data = textscan(fid,'%f')

celldisp(data)

If you need to read the data into normal two dimensional array use:

data = fscanf(fid, '%f')

Add a comment
Know the answer?
Add Answer to:
Hi, i am working with MATLAB. I have a text file from which I have to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to read from a file with with text as follows and I am...

    I am trying to read from a file with with text as follows and I am not sure why my code is not working. DHH-2180 110.25 TOB-6851 -258.45 JNO-1438 375.95 CS 145 Computer Science II IPO-5410 834.15 PWV-5792 793.00 Here is a description of what the class must do: AccountFileIO 1. Create a class called AccountFileIO in the uwstout.cs145.labs.lab02 package. (This is a capital i then a capital o for input/output.) a. This class will read data from a file...

  • . PART 3 – Output matrix data to text files using low-level File I/O What happens...

    . PART 3 – Output matrix data to text files using low-level File I/O What happens when you try to use the dlmwrite function with a delimiter that is more than one character? For example, say we require that the file must have two pipe symbols (I 1) between each value? For this part, you will need to output a magic square to a text file, but you will need to use low-level File I/O functions so that you can...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • Help with my code: The code is suppose to read a text file and when u...

    Help with my code: The code is suppose to read a text file and when u enter the winning lotto number it suppose to show the winner without the user typing in the other text file please help cause when i enter the number the code just end without displaying the other text file #include <stdio.h> #include <stdlib.h> typedef struct KnightsBallLottoPlayer{ char firstName[20]; char lastName[20]; int numbers[6]; }KBLottoPlayer; int main(){ //Declare Variables FILE *fp; int i,j,n,k; fp = fopen("KnightsBall.in","r"); //...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

  • In c++. I have 6 different text files that I want my program to read during...

    In c++. I have 6 different text files that I want my program to read during different runs. How would I make it so that i can read a select whichi file I want it to read during each run?

  • I am confused on how to read valid lines from the input file. I am also...

    I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well. Purpose        Learn how to use Java input/output. Due Date       Per the Course at a Glance. Can be resubmitted. Submissions           In this order: printed copy of...

  • C Programming: I have a text file which has this on it 1 2 3 4...

    C Programming: I have a text file which has this on it 1 2 3 4 5 6 I want my output to display 123456 How do I do this?

  • Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for...

    Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for writing and reading from console #include <fstream> //this one to deal with files, read and write to text files using namespace std; int main() { //first thing we need to read the data in the text file //let's assume we have the reading in a text file called data.txt //so, we need a stream input variable to hold this data ifstream infile; //now we...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT