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!