0

I have a list of dates and corresponding numerical values I'd like to parse into an array, but I can't seem to find a method to place the date strings as an array element. For example, using 3 numerical values, a minimal idea of what I'm trying is

data_date = '08/15/2003';
num1 = 56;
num2 = 23;
num3 = 2;

array = [data_date, num1, num2, num3];

A row in the desired array would look like

08/15/2003,56,23,2

To be specific, I'm writing this array to a file, so the above row is really the desired formatting in a CSV file.

2 Answers 2

1

Cell array is what you need.

data_date = '08/15/2003';
num1 = 56;
num2 = 23;
num3 = 2;
array = {data_date, num1, num2, num3};
Sign up to request clarification or add additional context in comments.

Comments

0

In more recent versions of MATLAB, you could also use table for this.

t = table({'08/15/2003'; '08/16/2003'}, [56; 57], [23; 24], [2; 3]);
writetable(t, 'tmp.csv')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.