How to select number in csv file if different than 0 and refer to another column to calculate the difference?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I know the question isn't clear but: I have a csv file containing data from graphs from a video. Those are values from each frame from the video. Using excel, I chose the values higher than a certain number, thus I have holes in my matrix (which is what I want).
The first column corresponds to a distance, which is my x. The second column corresponds to grey values, which is my y from the first frame of my video. The third column corresponds to grey values, which is my y from my second frame from my video, and so on.
What I would like to have at the end it's a graph size of my object in y versus the time (so my frames). So I am trying to have a code like:
If Y is different from 0 in frame 1, then Xmax-Xmin in the first column
But I need to learn how to write this code.
If anyone has an idea, it would be great! Thanks for your help!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1262620/image.jpeg)
0 commentaires
Réponses (1)
Jayant Gangwar
le 18 Jan 2023
Hi,
First you need to import the data to MATLAB, you can use 'readmatrix', refer to this documentation for more information about this function.
After you have the data in a matrix you can use 'if' statement to check if your condition is satisfied and then use 'max' & 'min' functions to do the calculation you require. Refer to below documentation for more information about these functions-
For example the code would look similar to the following
>> mat = readmatrix('my_data.csv');
>> if(Y!=0)
>> var = max(mat(:,1)) - min(mat(:,1));
>> end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!