Filter löschen
Filter löschen

Matlab: Text files, Read header lines and Cell references

1 Ansicht (letzte 30 Tage)
Matlab User
Matlab User am 16 Aug. 2016
Bearbeitet: Matlab User am 31 Aug. 2016
Hi,
I am trying to cell reference header lines from the code below. I was a able to read header information line by line and printed tLine into command window. my problem is that when i cell referenced tLine(6) in the command window even though the tLine has been outputted to command window.
I got error message: >> tLine{6} Cell contents reference from a non-cell array object.
any help on how i can fix this error message?
Thanks,
  4 Kommentare
Matlab User
Matlab User am 16 Aug. 2016
Bearbeitet: Matlab User am 16 Aug. 2016
Deeply sorry, I value your time and dedication here.
Benjamin
Benjamin am 16 Aug. 2016
@Stephen Cobeldick, this user is obviously new to MATLAB Answers. Maybe we shouldn't yell at them and make them afraid to ask for help.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Benjamin
Benjamin am 16 Aug. 2016
The problem is that you're trying to referencing tLine as a cell array, but it's a string since you use fgetl, which returns a string:
function tline = fgetl(fid)
%FGETL Read line from file, discard newline character.
% TLINE = FGETL(FID) returns the next line of a file associated with file
% identifier FID as a MATLAB string.
When you get C from textscan, you get your cell array:
%function [varargout] = textscan(varargin)
%TEXTSCAN Read formatted data from text file or string.
% C = TEXTSCAN(FID,'FORMAT') reads data from an open text file identified
% by FID into cell array C.
  11 Kommentare
Benjamin
Benjamin am 17 Aug. 2016
Type dbstop if error into the command window. When it errors, it will go into the editor and you can see what the value of tLine is. It is clearly not a character as it should be.
Guillaume
Guillaume am 19 Aug. 2016
@Matlab User, to solve your problem:
  • step 1: accept Benjamin's answer
  • step 2: start a new question about (and only about) your new problem. Make sure that you use the {} Code button to format the code in your question properly.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by