Index Out of Bound for 1x1 Array
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
David Hill
il 10 Gen 2022
Use readmatrix
data1 = readmatrix('4665_10.85.txt');
3 Commenti
Image Analyst
il 12 Gen 2022
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
il 12 Gen 2022
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
il 12 Gen 2022
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
Vedere anche
Categorie
Scopri di più su Data Import and Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!