Index Out of Bound for 1x1 Array
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to use importdata() method to put the datas within the attached .txt file into an array; data1.
data1 = importdata('4665_10.85.txt');
However, when reshaping it for mean calculation, it shows:
error: data1(6400,_): out of bound 1 (dimensions are 1x1)
I fundamentaly understand the what that means in a sense but as this syntax is very new to me, I am unsure of how I can troubleshoot this.
Subsequent actions after importing the data into the array includes:
ave_number=50;
v1=reshape(data1(1:128*ave_number,3),[128,ave_number]);
v1_ave=mean(v1.');
xx=5.5:0.043:11;
figure(1)
plot(xx,v1_ave);
ylim([0 5])
grid on; hold on;
[minal,idx]=min(v1_ave);
idx
Thank you for any assistence in advance!
댓글 수: 0
답변 (2개)
David Hill
2022년 1월 10일
Use readmatrix
data1 = readmatrix('4665_10.85.txt');
댓글 수: 3
Image Analyst
2022년 1월 12일
Well the format might need to be consistent. If they are spectroscopic files, can you get the data in standard .spc format so you can use GSTools?
Walter Roberson
2022년 1월 12일
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/858645/4665_5.5.txt';
opt = detectImportOptions(filename);
T = readtable(filename, opt);
data1 = table2array(T);
data1(1:5,:)
Image Analyst
2022년 1월 12일
Well the format might need to be consistent. You seem to have multiple images in there (not sure how many) and they can have different numbers of rows and columns.
If they are spectroscopic files, can you get the data in standard .spc format so you can use GSTools?
I think you're missing some data.
data = readmatrix('4665_5.5.txt');
% Get number of rows and columns from last row
rows = data(:, 1)
columns = data(:, 2)
signal = data(:, 3);
oneStretches = rows == 1;
[~, numImages] = bwlabel(oneStretches)
% Measure locations of the 1's
props = regionprops(oneStretches, 'PixelIdxList');
% See that the signal is rows*columns long.
numValues = numel(signal)
for k = 1 : length(props)
theseLocations = props(k).PixelIdxList;
firstRow = theseLocations(1)
if k == length(props)
lastRow = numValues
else
nextLocations = props(end).PixelIdxList;
lastRow = nextLocations(1) - 1
end
thisSignal = signal(firstRow:lastRow);
rows = data(lastRow, 2);
columns = data(lastRow, 1);
fprintf('This image should be %d by %d.\n', rows, columns)
spectralImage = reshape(thisSignal, rows, columns);
figure
imshow(spectralImage, []);
axis('on', 'image')
impixelinfo;
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!