Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! im trying to develop a matlab code that inputes a text file, ignores hashtag

ID: 3747162 • Letter: H

Question

Hi! im trying to develop a matlab code that inputes a text file, ignores hashtags and stores the data into different variables to later use it..... I would really appreciate a guidance i'm new at matlab

heres the text file... it was in txt format

# number of external forces and moments
2 1
# coordinates of the points at which external forces are applied
# x    y    z
0.0 1.0 1.0
5.0 3.0 0.0
# magnitude and direction of external forces
# F   dx   dy    dz
11.0 3.0 2.0 -9.0
0.1 3.0 1.0   1.0
# location at which external couple moments are applied
# x    y    z
0.0 1.0 1.0
# magnitude and direction of external couple moments
# M   ux    uy   uz
10.0 4.0 -2.0 9.0
# location of supports
# x    y    z
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
0.0 1.0 0.0
0.0 1.0 1.0
1.0 1.0 0.0
# type (F/M) and direction of reaction
# type dx    dy    uz
F      1.0   6.0 -7.0
F     4.0   1.0   1.1
F      1.0   8.0   1.0
F      6.0   1.0   0.0
M      0.0   9.0   1.0
M     -1.0   1.0   0.0

Explanation / Answer

This can be done in a lot of ways depending on your requirement. First of all, for starters, i would suggest you to look at the functions: fgetl , fgets , fscanf as you will find them to be the most useful for your context. Stripping numeric data is one thing, and depends on the file format i.e. the header, the content etc.. If this is a one time job, the program has to be designed that way, otherwise, a lot can be assumed for the file format.

File opening and closing is done with fopen and fclose with a fileID handle to the intended file (similar to C)

What i would suggest is to look into fscanf for example:

To skip specific characters in a sample file, and return only numeric data:

Assume the file hash.dat contains: '78# 72# 64# 66# 49#'' as a string.

Open the file with specified mode (similar to C)

fileID = fopen('hash.dat','r');

Read the numbers in the file, skipping the '#' (Note the usage of type specifier %d). Also return the number of values that fscanf reads.
[A,count] = fscanf(fileID, ['%d' '#']);

This will strip the numbers 78 72... from the text and store them in the variable A.

close the file
fclose(fileID);

For any clarification, please comment

Hope this helps! PLEASE THUMBS UP!!!!!!!!!!!!!!!!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote