Error, Index in position 2 exceeds array bounds!!

When I start loading my text file I get this error how to resolve? the text file is attached. And I am getting this error :
Index in position 2 exceeds array bounds.
Error in damping (line 12) freq=dm(:,1);
close all
clear all
% LOAD DATA OBTAINED FROM FEA ANALYSIS load Sp.txt; dm= Sp; freq=dm(:,1); amp=dm(:,2);

1 件のコメント

Walter Roberson
Walter Roberson 2018 年 9 月 15 日
Please do not close questions that have an Answer

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

 採用された回答

Adam Danz
Adam Danz 2018 年 9 月 14 日

0 投票

My bet is that dm is empty which would imply either that your Sp.txt document is empty or it's not loading correctly.
dm = [];
dm(:,1)
Index in position 2 exceeds array bounds.

7 件のコメント

zainab malik
zainab malik 2018 年 9 月 14 日
No its not empty here is the file
zainab malik
zainab malik 2018 年 9 月 14 日
How may i load it correctly kindly help me out.
Adam Danz
Adam Danz 2018 年 9 月 14 日
Step 1: understand what load() does and why that doesn't work with txt files. Please don't skip this step.
help load
Step 2: understand how dlmread() works.
help dlmread
Step 3: instead of using load(), use dlmread() with your txt file. I've tested it with your data and it works perfectly.
zainab malik
zainab malik 2018 年 9 月 14 日
Mismatch between file and format character vector. Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> ÿþ1 0 8 . 8 3 E - 0 5 \n
Error in damping (line 10) dlmread('Sp.txt');
I am getting this error when i use dlmread as:
dm = dlmread('Sp.txt'); freq=dm(:,1); amp=dm(:,2); figure(1)
Adam Danz
Adam Danz 2018 年 9 月 14 日
編集済み: Adam Danz 2018 年 9 月 14 日
This is weird. If I cut and paste your entire Sp.txt document into a new text file, the code works. But if I use your original file, it results in the error you shared.
I attached the identical copy-pasted file I used that works.
dm = dlmread('SpDanz.txt');
zainab malik
zainab malik 2018 年 9 月 14 日
Thank you sooooooo much. May be when i converted data from excel file to txt file at that time i used a wrong .txt type. Thats why it was not working I used Unicode.txt. Thanku very much :)
Walter Roberson
Walter Roberson 2018 年 11 月 14 日
Sorry, just noticed the content of the question now. The original file is in UTF 16 Little Endian encoding.
You can use my csv2table from This Posting . You will need both files I posted there.

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

その他の回答 (0 件)

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by