Error using interp1 with cell data

14 ビュー (過去 30 日間)
Jorge Bastillo
Jorge Bastillo 2015 年 4 月 29 日
コメント済み: Jorge Bastillo 2015 年 4 月 29 日
I have a .txt file with two columns of data. I run the following to open it and assign x and y:
%Open file and extract x and y data
fid=fopen(fileput,'r');
data=textscan(fid,'%d %d','headerlines',1);
x=data{1};
y=data{2};
fclose(fid);
My problem is when I attempt to use interp1 to find a value...
>> interp1(x,y,100)
Error using interp1 (line 130)
Values must be of type double or single.
I'm assuming it's got something to do with how I've assigned x and y, I've tried cell2mat(x) and got this error:
>> cell2mat(x)
Cell contents reference from a non-cell array object.
Error in cell2mat (line 42)
cellclass = class(c{1});

採用された回答

Image Analyst
Image Analyst 2015 年 4 月 29 日
What is data? Is it a cell array instead of an N by 2 array of doubles? If that's the case, you might try
x = data{:, 1}; % Extract contents of column 1
y = data{:, 2}; % Extract contents of column 2
If that doesn't work, show us what this displays in the command window:
whos data
whos x
whos y
  6 件のコメント
Jorge Bastillo
Jorge Bastillo 2015 年 4 月 29 日
File
Jorge Bastillo
Jorge Bastillo 2015 年 4 月 29 日
WOW... changing it to %f worked.
Thanks guys!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by