Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to Matlab and this should be a stupid question.

So the thing i wanted to do is to increment a number if a variable is true, in which i would be using that number to in the for loop. let me give you an example.

global var1;
var1 = true;
while (var1)
   var2 = 2;
   var2 = var2+1
   for var3=1:var2
       do something...
   end
end

so var2 should give me incremented number from 2 till the while loop is false.

I have tried a lot but just not able to get it.

could any one help me?

thanks in advance.

Update

so there are two buttons, start and stop and handles.h.data is a 128x14 matrix generated every 0.5 seconds from an Emotive EEG device, so this variable out updates every 0.5 seconds.

So when ever i press on the stop button i want this loop to end. Is this correct?

function start_Callback(hObject, eventdata, handles)
% hObject    handle to start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global true_false;
true_false = true;
a =1;
axes(handles.eeg_dynamic)
while (true_false)

    out = nan([size(handles.h.data),4]);
    for k = 1:a % a to be incremented by 1
        out(:,:,k) = handles.h.data + rand(1);
        plot(out(:,:,k));
        pause(0.5);
    end
    a=a+1;
end


% This converts the above out to 1D matrix and puts it in the workspace
axes(handles.eeg_final)
for eeg = 1:size(out(:,:,:),3)
        eeg_output_1d = permute(out,[1 3 2]);
        eeg_output_1d = reshape(eeg_output_1d,[],size(out,2),1);
        plot(eeg_output_1d);
        assignin('base','eeg_output_1d',eeg_output_1d)
    end

% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject    handle to stop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global true_false;
true_false = false;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
235 views
Welcome To Ask or Share your Answers For Others

1 Answer

These two lines

var2 = 2;
var2 = var2+1

are the same as

var2 = 3;

Perhaps you meant for var2 = 2; to go outside the loop?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...