Creating an array from .CSV file data

Hi, I am trying to put the outcome for every piece of data in to one array. The current file I am calling has 89 data samples. However this can change depending on what file the user selects. Do I use an empty array or how do I achieve this?
Array = {}
data = readmatrix(fullfile(path,file)); % Read data from selected file
dataStart = sscanf(input('Enter what row from the file you want the data to begin: ', 's'), '%d');
dataEnd = sscanf(input('Enter the amount of data samples in the data file: ', 's'), '%d');
for i = dataStart:dataEnd
Data1 = data(i,1);
Data2 = data(i,2);
Data3 = data(i,3);
Data4 = data(i,4);
Data5 = data(i,5);
Data6 = data(i,6);
Data7 = data(i,7);
Data8 = data(i,8);
Data9 = data(i,9);
Data10 = data(i,10);
Data11 = data(i,11);
Data12 = data(i,12);
Data13 = data(i,13);
if val3 <= 3 & val5 <= 0
Outcome = 'True';
elseif Datal3 <= 3 & Data1 > 0 & Data4 <= 0 & Data10 <= 0.9 & Data3 <= 1 & Data5 <= 268
Outcome = 'False';
elseif Data3 <= 3 & Data5 > 0 & Data9 <= 0 & Data10 <= 0.9 & Data3 <= 1 & Data6 > 268
Outcome= 'True';
%% ...There are more elseif conditions but I have removed them for this
end
Array = ({Outcome})
end
disp(Array)

4 Comments

I'm confused what exactly you're trying to do.
'I am trying to put the outcome for every piece of data in to one array.'
This seems like you're trying to combine several arrays into one large array, but in your code you only have one array, and your end result, 'Array,' is only going to be a single word. The output portion of this can be fixed by simple indexing, but I don't understand how the first part fits with what you're asking for.
'The current file I am calling has 89 data samples.'
It seems like you have this handled fine by asking the user to input the values.
'Do I use an empty array or how do I achieve this?'
Using an empty array is fine, just remember to index or you will overwrite your answer each time you complete the for loop.
Hi apologies, I probably didnt make it clear.
So after each sample of data is passed through the large if statement decision tree, a 'True' or 'False' outcome will be decided.
So I want to create an array with all these outcomes together if that makes sense?
@McGee —
To save either ‘Outcome’ or ‘Array’, with respect to ‘i’, subscript them:
Outcome{i} = 'True';
and so for the others, or:
Array{i} = Outcome;
depending on what you want as the result.
You can also just save them as 1 (true) or 0 (false) and be able to use them as a logic array during further analysis. Indexing still applies, you just don't have to save them as a string.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2019b

Asked:

on 20 Nov 2019

Commented:

on 20 Nov 2019

Community Treasure Hunt

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

Start Hunting!