Error in tgspcread and reshape
2 views (last 30 days)
Show older comments
I have been encountering some difficulty processing my data in MATLAB for 14 of 40 files fail because of the following two errors. I have included the full scripts/functions in the hope someone can tell me where I'm going wrong. I am uncertain why it works for most but not all. Please help?
extract_data_AJ
%% PNT2_DMSO_50uM_5
cd('/Users/Ewan/Desktop/MATLAB')
mkdir('PNT2_DMSO_50uM_5')
cd('PNT2_DMSO_50uM_5')
[PNT2_DMSO_50uM_5,shift,ratio1,ratio2,output]= extract_lipid_fixed_AJ('/Users/Ewan/Desktop/MATLAB/PNT2 cm5/PNT2 50uM DMSO x55 y43.spc',55,43);
close all
save('/Users/Ewan/Desktop/MATLAB/Extracted files/PNT2_DMSO_50uM_5.mat')
clear
Function - extract_lipid_fixed_AJ
function [extracted_spectra ,shift,ratio1,ratio2,output]= extract_lipid_fixed_AJ(filename,x,y)
%%e.g. filename = 'C:\Users\laure\Dropbox\CENSIS postodc\Lipid big experiment\27022017 Dreadnought\PC3 DMSO 0.5s 50% centre3000 2 x59y39_Copy_Copy.spc'
%% read in spc file change file
tgspcread(filename)
%% assign shift and data variables from spc file
shift=ans.X;
data=ans.Y;
%% change dimensions according to map
%x=59;
%y=39;
%% reshape data to match original image
data=data';
data = reshape(data, x, y ,[]);
data=rot90(data,-1);
data=fliplr(data);
imagescnan(sum(data,3));axis image;
%% select cell area
ti = sum(data,3);
[level,mask] = thresh_tool(ti);
maskrows = reshape(mask, [], 1);
data = reshape(data, y*x,[]);
mask_1_rows = find(mask == 1);
data_maskrows = data(mask_1_rows,:);
emptymatrix = NaN(y*x, length(shift));
emptymatrix(mask_1_rows,:) = data_maskrows;
output = reshape(emptymatrix, y, x, []);
imagescnan(sum(output, 3));axis image
close all
%% plot average spectrum
output = reshape(output,[],1);
rows_of_spectra = find(output==output);
extracted_spectra = output(rows_of_spectra,:);
extracted_spectra = reshape(extracted_spectra,[],length(shift));
figure; lplot(shift, mean(extracted_spectra));
%% reshape
image = reshape(extracted_spectra,[],1);
matrix = NaN(y*x,length(shift));
matrix = reshape(matrix,[],1);
matrix(rows_of_spectra,:)=image;
image = reshape(matrix, y, x, []);
%% ratio 1 map = 2850/2935
image=reshape(image,y*x,[]);
[a b]=size(image);
intensity_2850=image(:,418);
intensity_2935=image(:,355);
for i=1:a
ratio1(i,1)=intensity_2850(i,1)/(intensity_2935(i,1));
end
ratio1=reshape(ratio1,y,x,1);
imagescnan(ratio1); axis image; set(gca,'FontSize',20,'FontName','Arial');colorbar;caxis([0 1.0]);colormap(jet);
print('-dtiffn','-r600','Ratio1.tif');
close all
%% ratio 2 map = 2880/2935
intensity_2880=image(:,396);
intensity_2935=image(:,355);
for i=1:a
ratio2(i,1)=intensity_2880(i,1)/(intensity_2935(i,1));
end
ratio2=reshape(ratio2,y,x,1);
imagescnan(ratio2); axis image; set(gca,'FontSize',20,'FontName','Arial');colorbar;caxis([0 1.0]);colormap(jet);
print('-dtiffn','-r600','Ratio2.tif');
close all
end
Error 1 - Reshape
>> extract_data_AJ
Reading header for file: /Users/Ewan/Desktop/MATLAB/PNT2 cm5/PNT2 50uM DMSO x55 y43.spc
File contains 1596 scans
ans =
struct with fields:
Header: [1×1 struct]
X: [633×1 single]
Y: [633×1596 single]
Z: [1×1596 single]
Error using reshape
Product of known dimensions, 2365, not divisible into total number of elements, 1010268.
Error in extract_lipid_fixed_AJ (line 15)
data = reshape(data, x, y ,[]);
Error in extract_data_AJ (line 5)
[PC3_DMSO_5uM_1,shift,ratio1,ratio2,output]= extract_lipid_fixed_AJ('/Users/Ewan/Desktop/MATLAB/PNT2 cm5/PNT2
50uM DMSO x55 y43.spc',55,43);
Error 2 - tgspcread
extract_data_AJ
%% PNT2_5uM_TOFA_1
cd('/Users/Ewan/Desktop/MATLAB')
mkdir('PNT2_5uM_TOFA_1')
cd('PNT2_5uM_TOFA_1')
[PNT2_5uM_TOFA_1,shift,ratio1,ratio2,output]= extract_lipid_fixed_AJ('/Users/Ewan/Desktop/MATLAB/PNT2 cm1/PNT2 5uM TOFA x66, y87..spc',66,87);
close all
save('/Users/Ewan/Desktop/MATLAB/Extracted files/PNT2_5uM_TOFA_1.mat')
clear
>> extract_data_AJ
Reading header for file: /Users/Ewan/Desktop/MATLAB/PNT2 cm1/PNT2 5mM TOFA x66, y87.spc
File contains 5742 scans
Operands to the || and && operators must be convertible to logical scalar values.
Error in tgspcread (line 313)
if(headeronly) || subheader(traceCount).subtime < zrange(1) || subheader(traceCount).subtime > zrange(2)
|| ~ismember(traceCount,scanindices)
Error in extract_lipid_fixed_AJ (line 6)
tgspcread(filename)
Error in extract_data_AJ (line 5)
[PC3_DMSO_5uM_1,shift,ratio1,ratio2,output]= extract_lipid_fixed_AJ('/Users/Ewan/Desktop/MATLAB/PNT2 cm1/PNT2
5mM TOFA x66, y87.spc',66,87);
Any expert help would be much appreciated :)
2 Comments
Rik
on 20 May 2019
Do not delete the contents of your question. If you want private help, hire a consultant. If you want free help on this forum, keep your post up as it was so others can benefit as well. Removing your question after it has been answered is extremely rude.
Answers (1)
Pavel
on 15 Feb 2019
Error 1:
This may be related only to variable data, it have such size that can't be reshaped to desired numbers of rows (x) and columns (y).
data = reshape(data, x, y ,[]);
Error 2:
I'm guessing that you use one of the past MATLAB release, because debugger told about error at 313 line with the following code, while it located on 321 line of file tgspcread.m in latest release 2018b.
if(headeronly) || subheader(traceCount).subtime < zrange(1) || subheader(traceCount).subtime > zrange(2)
So this error can be a bug in older version of function tgspcread. There are two ways: try to debug this function on your own or try to use a newer version of MATLAB.
If you choose first variant, you can find the code with "edit" command:
edit tgspcread
0 Comments
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!