Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Help

  1. Sep 4, 2010 #1
    for ii=1:1:3 % start looping

    rand_id= rand(1,1) *3; % Randomly generte a number between 1 to 3.

    if (rand_id<1)
    rand_id=1; % 0 is ommitted.
    else rand_id=floor(rand_id);

    % rand_id will be used to open a previously saved file randomly.

    if (rand_id==1)
    f_id_1=fopen('fire.txt','r');% Open and read a file.
    elseif (rand_id==2)
    f_id_1=fopen('flood.txt','r'); % Open and read a file.

    %saning the file to read the text.
    events_1=textscan(f_id_1, '%s', 'Delimiter', '\n');
    events_1=events_1{1}; % saving the text.
    rand_event=events_1{randi(numel(events_1))}; % selects one text randomly.


    I wrote the above code to randomly select a file. The file contains number of sentences. My aim is to randomly pick a sentence . I did that. Now, my problem is I cant save all the picked sentences inside the loop.

    When I declare S(ii)=rand_event. It shows error. When I try S(ii)=rand)event(ii). It only retruns 1, 2, 3 characters in the three loops.

    Please help.
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted