code folding issue

Hi there,
I've had some difficulties lately with code folding, specifically for cells. Using code folding for cells is useful as it allows me to breakup rather long scripts into various segments. In such cases, these segments contain various for and if and try loops.
A recent example script contains a sitaution where I had approximately 100 lines of code in one cell (with code folding working), and then a similar one right below it (also with code folding that was working). Then, below that, I would type:
%% please make new cell for me
And I would see no evidence of any code folding or any new cell creation.
There have been a few other situations of inconsistent activity I have seen with respect to code folding and cells (in particular with long scripts). Does anyone know what the soruce of this might be, and how I can write amy scripts in a way that would make this not happen?
Its worth noting that my script (from what I can see) has no major syntax errors (and there is an end statement wherever there is supposed to be one). Its also worth noting that at the beginning when I began to approach this issue, the first two cases of code folding weren't working either... I found that avoiding certain aspects of syntax seemed to help (such as avoiding one line for / end loops for example). I don't know why this helped.
It seems to be that code folding is a bit inconsistent and I might have to give up on it as a strategy for managing long scripts.
Thanks so much, Ben

5 个评论

Is it possible for you to post a small example that exhibits the problem, rather than just a description? The description by itself is not making it clear to me.
Thanks! here is an example. The first three cells work, the last doesn't.
%%
bvqx = actxserver('BrainVoyagerQX.BrainVoyagerQXScriptAccess.1')
root='F:\Users\ben\fMRI analysis\'
conditions={'fam_iden', 'fam_nrb', 'fam_unf', 'fict_unf',...
'sem', 'sem_parametric','conf', 'error'}
subjects={'bb'};
famfilename='respXtype'
occfilename='corVSincor'
newfilename='A7'
%% familiarity judgments
noNRB=[]
for x=1:size(subjects,2)
for y=1:5
famerrorcode=0;
occerrorcode=0;
vmrfilename=strcat(root, subjects{x}, '\anatomical\',...
subjects{x}, 'anat_SAG_ISO_TAL.vmr')
famvtcfilename=strcat(root, subjects{x}, '\BV files fam\', ...
subjects{x}, '_FAMrun', num2str(y),...
'_3DMCTS_LTR_THP3c_SCSAI2_talairach.vtc')
vmrproject = bvqx.OpenDocument(vmrfilename);
bvqx.ResizeWindow(600,400);
vmrproject.LinkVTC(famvtcfilename);
vmrproject.LinkStimulationProtocol(strcat(root, subjects{x}, '\BV files fam\' ,famprtname));
famprtname=strcat( subjects{x}, '_', famfilename, '_run', num2str(y),'.prt')
ee=bvqxfile(strcat(root, subjects{x}, '\BV files fam\' ,famprtname))
try
if ee.Cond(5).OnOffsets==[0 0];
famerrorcode=1 ;
end;
catch %#ok<CTCH>
end
end
end
%% new cell that doesn't work
I'm a little confused. There's no code in that last cell. If I put a single line of code there, it will fold. Maybe I misunderstand what you are expecting?
Thanks again, actually I think you understood well what I am trying to do.
So after some more fiddling, I believe I've isolated the issue. When i tried to write "%% new cell that doesn't work" (as above), no cell was created.
But, if I copy and paste the code elsewhere (in this box or in an MS document), and then copy and pasted it BACK into the editor, it now properly code folds the cell. I believe this must be a bug in Matlab.
I had cases like yours in the past but it's really hard to reproduce the same behaviour for others...then it's hard to detect and solve.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by