Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ep03: generating file names for csv files and figures with sprintf #108

Closed
gcapes opened this issue May 22, 2018 · 4 comments
Closed

Ep03: generating file names for csv files and figures with sprintf #108

gcapes opened this issue May 22, 2018 · 4 comments

Comments

@gcapes
Copy link
Contributor

gcapes commented May 22, 2018

What is the learning objective for this section? It seems rather clunky and hard to motivate.

A neater solution is suggested in the following exercise, but no solution is given, and subsequent episodes use the sprintf script.
In order to achieve the same task, I suggest using the dir command to generate a list of files to load, then use the replace command twice to generate the image file names.

I'm happy to submit a PR, but also want to check that it won't remove a learning objective. All I can think of is that sprintf won't have been covered.

@shwina
Copy link

shwina commented May 22, 2018

Can you provide a quick preview of what the code would look like with dir? Does dir have the same behaviour on all platforms?

@gcapes
Copy link
Contributor Author

gcapes commented May 22, 2018

The file name generation bit would look like this, and the rest of the script would be unchanged.

file_list = dir('*.csv');
for i = 1:length(file_list)
	data_file = file_list(i).name;
	img_file = replace(data_file, '.csv', '.png');
	img_file = replace(img_file, 'inflammation', 'patient_data');
end

I'd need to check that dir doesn't do anything different on Mac or Windows.

@shwina
Copy link

shwina commented May 22, 2018

I think that looks fantastic, but remember that file_list here is a Cell Array (is that right?) that we haven't introduced. The dot operator is also new.

I'm completely in favour of introducing Cell Arrays before this section though.

@gcapes
Copy link
Contributor Author

gcapes commented May 22, 2018

Cool! file_list is a structure array, which of course will need explaining. I'll put something together and submit a PR for discussion.

gcapes added a commit to gcapes/matlab-novice-inflammation that referenced this issue May 25, 2018
- Use the existing exercise as the lesson example
- Explain structure arrays
- Discuss portability of code

Fix swcarpentry#108.
gcapes added a commit to gcapes/matlab-novice-inflammation that referenced this issue May 25, 2018
- Use the existing exercise as the lesson example
- Explain structure arrays
- Discuss portability of code

Fix swcarpentry#108.
zkamvar pushed a commit that referenced this issue Apr 26, 2023
- Use the existing exercise as the lesson example
- Explain structure arrays
- Discuss portability of code

Fix #108.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants