I have the following image stored as f7.fig. I want to open it again and delete all the other entries except the first (red), second (blue) and last(cyan). I want also to delete them from the legend. Is this possible?
An easy interactive approach would be like this:
savefig(h, 'somefig.fig`); % Save figure
% Close the figure ...
openfig('somefig.fig'); % Open figure
% Click on the curves you wanted to delete ....
delete(gco); % delete object -> this takes care of the legend too
% Click on the curves you wanted to delete ....
delete(gco);
% so on...
This approach here is also an alternative.
Related
I want to create one figure that shows two plots. But not as a normal subplot(1,2,1) that will create two "parallel" panels. Instead I want one figure to be small and located in a corner of another one.
Let's assume the main figure is something as simple as:
h1=fplot(#(x) 2*x +1.4*x^2 -0.8*x^3,[0 1]);
hold on;
h2=fplot(#(x) 0.5*x +1.8*x^2 -1.2*x^3,[0 1]);
legend('line 1','line 2','location','southeast');
One more complication is: the second figure (the small one I want to be in the corner) is saved as "external" .fig file (I can easily import it with open example.fig, but it obviously opens as a new window).
I have an image of a table (in my case .gif) and want to extract the table it was (ideally, .ods).
Is there any way to do so? (doing it manually is discarted, since the table has more than 1000 rows and 6 columns)
Here is a part of the image / table:
You will be able to get most of it through OCR, but you'll need to manually verify the data and fix some inaccuracies that will be there. It definitely won't be perfect.
First thing to do is to ensure you have a good quality image for the OCR software:
Here's what I did with your sample png (I'm using Windows):
I opened the image in The Gimp.
Removed the orange/blue backgrounds:
a) Select -> By Color and clicked the blue background
b) I held down Shift and clicked the orange background (this will add it to the current selection)
c) Edit -> Fill With BG Color (this sets it to white)
d) Ctrl-Shift-A to cancel the selection
I removed the partially cut off '305' line:
a) used the Rectangular Select tool button from the palette, and filled the selection with BG Color, as above
Let's remove the table border:
a) Click the 'Fuzzy Select' tool button from the palette
b) Click somewhere on the table border (you should see the 'marching ants' instead of the border)
c) Edit -> Fill With BG Color
d) Ctrl-Shift-A to cancel the selection again
We need to increase the number of pixels that the numbers use so that the OCR can better detect their shapes
a) Image -> Scale Image. I chose to scale by 1000% with Linear Interpolation (the other interpolations won't work as well)
Download and install Tesseract from GitHub
a) At the command prompt type (include the double-quotes to cope with spaces within the path, & change your paths as necessary):
"D:\Program Files (x86)\Tesseract-OCR\tesseract" "d:\temp\your_image.png" "d:\temp\your_txt_file_output"
The output with be a text file with an appended .txt extension. It will still have a few artifacts but we can easily correct those in Notepad++ (or similar):
a) The commas were seen as full-stops, so I did a Find and Replace of "." with "," (I'm assuming you don't have any decimal points in the data!)
b) There were some spaces before a few commas, so I did Find and Replace " ," with "," (note I included a space before the comma in the Find)
c) There were still some spaces in the numbers, so I did a Find and Replace of " " with "" (a space with an empty replace)
This gave the following result:
298 299 300 301 302 303 304
910,820,000 920,820,000 930,820,000 941,820,000
952,820,000 983,820,000 9?4,820,000 210,000
220,000 220,000 220,000 220,000 220,000
220,000 2,500 2,500 3,000 3,000
3,000 3,000 3,000 19,000 19,000
20,000 20,000 20,000 20,000 20,000
Note the question mark in the place of 7 in the second block of text. Things like that still need to be tidied up.
Lastly, you'd copy and paste the rows of text into your spreadsheet etc.
I wanted to post another option I finally found online.
https://convertio.co/es/ocr/
Even though I think K Scandrett answer deserves to be the correct one, since it doesn't rely on a URL, which might go down.
If this is a one-time/rare need and you are windows OS user and you have a Microsoft Excel installed, the application supports extracting the image data to excel. Follow this link for the complete reference.
I'm an environmental engineer using TecPlot to plot come charts with some input data, let me explain my problem.
I'm studying the evolution of a river bed with a Fortran code which I wrote. As a output the code gives a detailed stratigraphy going some centimeters under the soils surface. Basically the output file looks like this:
0.03500000000 -0.18093000000 -0.17093000000 -0.16093000000 -0.15093000000 ...
0.10500000000 -0.18100000000 -0.17100000000 -0.16100000000 -0.15100000000 ...
0.17500000000 -0.18107000000 -0.17107000000 -0.16107000000 -0.15107000000 ...
0.24500000000 ...
and so on.
The first column is the x variable (horizontal evolution) and has 200 data.
The other columns are the evolution on the vertical coordinate.
So basically for each line we have, starting from the second colon, an horizontal line drawn thanks to 400 values.
For example if I plot the entire first column with the entire first row what I get is just a line on the plot.
For each time step my Fortran code create an output file which gives a plot with all the substrate lines.
What I want to do, and I really don't know how to do it, is animating this plots in order to have, for each time step of the animation, the ENTIRE plot with ALL THE LINES.
What I've done in TecPlot so far is:
1) import all the output files
2) put them in the XY Line plot of TecPlot using one zone for each output file I have (file 1 -> 1:ZONE001, file 2 -> 2:ZONE001, file 3 -> 3:ZONE001 and so on)
3) trying to turn them into contour plot (no results)
3.2) trying to animate them with XY Line plot animation (too bad, it animates every single line...)
I hope that I've been enough thorough to let you helping me.
I would appreciate each contribution and I thank You for each -even short, small- answer.
Best regards
Assuming you have already loaded the file, and have multiple zones. you can animate the mappings by Animate -> Mappings.., As far as
trying to animate them with XY Line plot animation (too bad, it animates every single line...)
is concerned, you need Map Skip value more than 1, to skip the mappings (lines). The animation can be saved as video or image sequences from the same dialogue box, by pressing the small video button besides the play rewind and forward buttons enter image description here
I define values for the variables and call the function, it returns the output image in the figure. But when i want to test another set of data, the output image will come out, it's together with the previous output image. How can i solve it, do i need to add what code at the end of the function file?
Either close all before your generate the new figure if you're not interested in the old output figure, or make a figure call before creating the new image to ensure it pops up in a new figure window. Or, you can overwrite the current open figure by setting hold off first, although that's specifically for graphs.
I am making a GUI for a program I have created, where I need to be able to change the position of a load along a beam. I have set up the axes and the slider properly, but I am unsure how to get the axes to update, as I can't find any examples that show how to do this on the internet.
At present, as I move the load, the position updates properly, but the old position stays on screen as well, which is quite annoying.
Can anyone recommend any good examples that show how to do this, or does anyone have a suggestion of how to go about refreshing the axes?
Here is the slider callback (I haven't included the create_fcn function). Also, theres a lot of comments in the code, as I used the Guide function to make the GUI.
Please note that the input to slider is a proportion of the overall beam length (as a decimal).
function PointLoadxx1posslider_Callback(hObject, eventdata, handles)
% hObject handle to PointLoadxx1posslider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
PLxx1pos = get(handles.PointLoadxx1posslider,'value');
set(handles.PLxx1posedit, 'String', num2str(PLxx1pos));
l = 3000; % This is the Length of the beam
zpl1 = get(handles.PointLoadxx1posslider,'value')*l;
% Multiplies the position decimal by the overall length
LoadPlotter(hObject,zpl1,handles) % Sends the command to the plot plot function
guidata(hObject,handles);
function LoadPlotter(hObject,zpl1,handles)
% The following draws the beam supports as lines
SH = l/20; %Height of supports
line([0 l], [SH/2 SH/2])
line([-SH/2 SH/2], [0 0])
line([-SH/2 0], [0 SH/2])
line([0 SH/2], [SH/2 0])
line([l-SH/2 l+SH/2], [0 0])
line([l-SH/2 l], [0 SH/2])
line([l l+SH/2], [SH/2 0])
xlim([ -100 l+200])
ylim([-l/2 l/2])
%Draw Load position
% zpl1 = get(handles.PointLoadxx1posslider,'value')*l;
% zpl1 = 0.5*l;
zpl2 = 0.2*l;
PL1 = 50;
%This is the value of the point load applied to the beam, which will
be an input from another slider
PL1Draw = line([zpl1 zpl1],[SH/2 PL1*10]);
% refresh(handles.axes1);
guidata(hObject,handles);
Obviously, I would like to keep the other lines drawn, but change PL1Draw as the slider is moved. Please can you explain what I am supposed to tag to do this?
Many thanks in advance.
James
I assume that you have plotted a beam, which is supposed to bend as you change the slider value. Since you are able to plot the new position into the axes, I assume that you know how to write callbacks. I further assume that there are parts of the plot that should stay the same, and parts that should change.
To change the parts that need changing, the easiest method is just to delete them and then to redraw. In order to delete specific items from a plot, it's best to tag them. Thus, your plotting would go like this
%# remove the old position
%# find the handle to the old position by searching among all the handles of
%# the graphics objects that have been plotted into the axes
oldPosHandle = findall(handles.axes1,'Tag','position');
delete(oldPosHandle);
%# plot new position
PL1Draw = line([zpl1 zpl1],[SH/2 PL1*10]);
%# add the tag so that you can find it if you want to delete it
set(PL1Draw,'Tag','position');
Note 1
To make the GUI respond faster (if needed), do not delete and re-plot, but change the 'XData' and 'YData' property of the old position object.
Note 2
If you aren't already doing so, put the plotting function (the one that updates everything in the plot, not just the position of the load) in a separate function, not into the callback of the slider, and have instead the slider callback call the plot function. This way, you can call the same plotting function from several buttons and sliders, which makes the code a lot easier to maintain.
EDIT
I have updated the commands. Note that there is no special 'tagging' function. 'Tag' is a property of every graphics object, like 'Units', or 'Color'. It simply helps you to label the graphics objects so that you don't need to remember the handles.
Unrelated to the actual question, but related to the project:
http://www.mathworks.com/matlabcentral/fileexchange/2170
This book is still available used on Amazon, it might save you a lot of the coding of the Mechanics of Materials stuff. I wrote this about 12 years ago as an undergrad, but I think the MATLAB code should still be functional.