error when using segment function

조회 수: 3 (최근 30일)
Emily
Emily 2025년 1월 19일
답변: Gayathri 2025년 5월 6일
I get these errors when running this snippet of code that references another script (script attached as a matlab file)
[filt_in, data_in_segs_corrected, segment_params]=segment_filt_v2(data_to_segment,[],[],params.genome_build);
params.segment_params=segment_params;
Warning: The data contains more columns (number of channels) than rows (number of samples). Check that the data is not transposed inadvertently.
> In ctrlMsgUtils.warning (line 25)
In segment (line 76)
In segment_filt_v2>seg_fun (line 145)
In segment_filt_v2 (line 101)
Unrecognized function or variable 'jmax'.
Error in segment (line 236)
hh=hist(:,jmax);
Error in segment_filt_v2>seg_fun (line 145)
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
Error in segment_filt_v2 (line 101)
data_in_segs_corrected{Chr}(in,c-4)=seg_fun(Data{Chr}(in,c), R2);
  댓글 수: 5
Emily
Emily 2025년 1월 19일
I had to subset this to be able to upload it, but it still gives the same error.
Mathieu NOE
Mathieu NOE 2025년 1월 21일
with the provided code and files I have this error message :
Unrecognized function or variable 'last_autosome'.
Error in segment_filt_v2 (line 70)
s=cell2mat(Data(1:last_autosome(genome_build)));

댓글을 달려면 로그인하십시오.

답변 (1개)

Gayathri
Gayathri 2025년 5월 6일
Hi @Emily,
I spent some time looking into the code, and I was able to face the same error as mentioned in your query.
The error is happening because for a certain case the data that goes into the "segment" function is a scalar. And when we try to retrieve the "size" of a scalar we get it as follows
And the function expects number of rows to be greater than columns, hence you receive the error mentioned.
I had modified the "seg_fun" function to identify the cause of the issue as shown below. You can also troubleshoot the issue by placing breakpoints in the "disp" command.
function data_out=seg_fun(data_in,R2)
% segment data
[tr1,tr2]=size([data_in,ones(length(data_in),1)]);
if tr1<=tr2
disp("error condition");
end
thm=segment([data_in,ones(length(data_in),1)],[0 1 1],R2); % function segment requires the System Identification Toolbox
thm=thm([1 1:end-1]); % correction: segment always results in a shift of 1 in the coordinates
% failed segmentation resulting in all NaNs: iteratively remove 5 data points at a time until resolved
nan=length(find(isnan(thm)));
iter=1;
while nan>length(thm)*0.9 % if most windows per region between gaps = NaN, remove additional 5 data points from beginning of region for each iteration
idx=5*iter;
% segment
[tr1,tr2]=size(data_in(idx+1:end));
if tr1<=tr2
disp("error condition");
end
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
thm=thm([1 1:end-1]); % correction: segment always results in a shift of 1 in the coordinates
thm=[NaN(idx,1); thm]; % add NaNs in the beginning
nan=length(find(isnan(thm))); % recount number of NaNs
iter=iter+1;
end
Pleaserefer to the screenshot below to get a better understand the cause of the issue.
For resolving the issue please refrain from calling the "segment" function when the data input is not in the required format.
And I also noticed that the data might be taken in different orders. Initially I faced the error around "sample 19, Chromosome 11", and next as shown in the screenshot.
I hope this helps in resolving the query. Please feel free to reach out in case of any queries. Thanks!

태그

Community Treasure Hunt

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

Start Hunting!

Translated by