Add new row to String Array.
Show older comments
Hi,
I have a Xx1 string array and I currently have something on the lines of:
strarray.full = [strarray.full;NEWDATA];
The code will add a new line each loop, and will re create the string array each time.
This works fine for smaller files, but the txt files I am reading are around 200,000 lines, so this takes around 20 minutes to run.
I am trying to get something like this to work to avoid having to re create the matrix each loop and make it alot faster.
strarray.full(end+1,1) = NEWDATA
I keep getting the Error "Unable to perform assignment becuse the indices on the left side are not compatible with the size of the right side"
The first loop results in an empty NEWDATA. I also do not believe I am allowed to share the code itself.
Thanks.
Accepted Answer
More Answers (1)
Adam Brabec
on 13 Jul 2020
0 votes
6 Comments
the cyclist
on 13 Jul 2020
If you are able to upload the data and code that is currently having such a long run time, maybe people could find a way to speed it up. 7 minutes still seems pretty long for just filling a string array. But you hadn't mentioned reading text files, so maybe that is the botteneck. You could use the profiler to investigate.
Adam Brabec
on 16 Jul 2020
the cyclist
on 18 Jul 2020
Edited: the cyclist
on 18 Jul 2020
Rather than post the format of a text file, can you just upload a sample text file with made-up data? Make it look as close to a typical file as possible.
How many files do you have, such that it takes 7 minutes to run your code? If you post one typical file, can I duplicate that one file many times in the directory to recreate your issue? Can you just upload a zip file with many files like that?
Do you see what I am doing here? I'm trying to make it is easy for me (and any other contributor here) to replicate exactly what is happening to you. Otherwise, you are leaving too much effort -- and too much guesswork -- that might inadvertently be spent on tasks that are not directly solving your actual problem.
Adam Brabec
on 18 Jul 2020
the cyclist
on 18 Jul 2020
Not frustrated, and I don't feel like I wasted my time. I'm just trying to help you get to a solution efficiently.
Just bear in mind that any work you leave for someone else, rather than doing that prep work yourself, has to be done by every person who tries to help you. So, it can be a hurdle that some people just won't bother with.
Adam Brabec
on 19 Jul 2020
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!