MATLAB Cutting .wav file from input difficulties - matlab

I'm experimenting with MATLAB currently and the first part that interested me was sound manipulation. I set out to design an interface so that I can kill two birds with one stone and learn both as I go along. So far I have been able to get the interface to load a file plot it and then play it all within the interface.
I now want to be able to take inputs from a potential user that will denote two seperate seconds in the sound clip and allow the user to cut that part of the clip out. So they will be left with the original clip/song then a new section from that song/clip. I will then move on to plot this later. My problem is that I am completely stumped on how to get the input from the user and get that to cut the clip.
Below I will show my code to load the file in so you can see the names given and then the code with which I tried to cut the clip.
First, names given(includes plotting)(I also load the file to an audio player):
[filename,pathname] = uigetfile('.wav', 'File Selector');
[sound,rate] = audioread([pathname,'/',filename]);
figure = plot(sound)
plot(handles.axes1,sound);
My attempt at getting inputs from two edit text boxes:
SectionStart = get(handles.SectionStartET, 'string');
SectionEnd = get(handles.SectionEndET, 'string');
FileSection = FS(SectionStart:SectionEnd);
global player2;
player2 = audioplayer(FileSection);
In the first two lines here, I'm getting the string from the edit text boxes. Then I tried to put the two together. Then I load the player. I feel like the syntax is wrong on the third line before the brackets but I can't find a good example online to help, hoping someone here can shed some light! Thanks in advance!
Everyone's viewing but not posting, if you need more info about the code let me know!

Related

how to save figure of gui plot which will run on a computer that does not have matlab

I have made a Gui program that I compile to EXE application which lots csv file into graph data. I buit a save button but I do not know how save figure with different name each time cause (savefig anduisave both uses matlab program). I am posting my code below if anyoff you guys figure out how to save gui figue into image or anything that does require matlab to open. Last function is the callback function for save button.
function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
%savefig
If you are trying to save a kind of image from your figure, then the best option which supports many aspects, is using print function.
I have already done this in a compiled app and it works perfect. Using print function you can set different file type(vector formats like *.svg are also supported), resolution(dpi), and so many others.
Although you can use print function directly on the figure, but I found that the best way (More Customization like removing or adding some objects and changing many options) is to follow this steps:
Create another figure with Visible='on' but a position that is out of screen with the same width and height of Main Figure.
normalized position = [-1, -1, ?, ?]. (Create this figure in start up and don't destroy it until your app exits, let call it Print Figure).
Copy your figure content (or the parts you are interested in) using copyobj to that figure (you may need to set Parent property of some key objects like panels to this new figure). They would look exactly as they look in the main figure, because they have the same properties. you can add or remove some objects in this step.
Change aspect ratio of "Print Figure" for a better output.
Print this figure with all options (file format, dpi, ...) you need. in my own GUI i allowed the user to change this settings with an input dialog.
In my app i used functions like winopen to show the output, and output directory to the user, when the print task was done. Print process takes some time, specially if dpi is huge, so it is also a good idea to inactivate buttons and show wait cursor.
Update:
a simple usage would be:
print(MainFigure, 'myFileName', '-dpng', '-r300')

Matlab: How to interact with a graph to define a range via GUIs

I'm currently trying to make a GUI that will allow a user to select a range of x-values, limited to a set of predefined "markers" that can appear on the graph of some data. The Matlab program has a bunch of data that's already delimited with some number of markers, and will ask the user to choose two of these markers as a start and stop point, and then continue from there.
My question is whether or not Matlab has a built-in function or object that will place some kind of interactive marker on the plot (preferably on the bottom of the graph so that it doesn't obscure the data) that the user can click on so that I can get a call-back function from it and see which marker the user chose (and also perhaps have the ability to change its color and such to represent its selection).
Preferably the answer will not involve any add-ons, but any answer and any help would be greatly appreciated. Thank you!
Here is a very simple example using ginput, which asks the user to select a starting and ending points from which to plot the data.
clear
clc
close all
x = 1:15*pi;
figure
plot(x,sin(x),'LineWidth',2);
uiwait(msgbox('Select a start and finish point'))
a = zeros(1,2);
[a,~] = ginput(2);
xStart = a(1);
xFinish = a(2);
set(gca,'XLim',[xStart xFinish],'XTick',round(xStart):1:round(xFinish))
Is it something like this you had in mind? Do you really need a callback or is this sufficient? If not could you elaborate on what kind of markers you would need?
Hope that helps!

Importing graphic data into text file MATLAB

I am trying to create a program in MATLAB by which I can click on an image (using the input command) and MATLAB outputs a graphic marker on the image, and stores the data to a text file.
The motivation for this comes the Major League Baseball Gameday App, as I want to use it for a similar purpose, but on the input rather than the receiving end. I have created a code which takes an image and outputs a graphic marker at the points clicked. However, I need to improve the code by (hopefully) color coding each marker according to a manual input (maybe using the reply function?) and also numbering each marker. Also, I would like it to output the reply, location, and number to a text file which can be saved for later.
The code I have is below (with comments explaining what is missing), any help is appreciated.
img=imread('Path/Filename.png');
image(img);
title('Pitching')
ginput
%ask for reply of text between each click
M=[ans];
N=length(M);
hold on
for i=1:N
plot(M(i,1),M(i,2),'o','MarkerFaceColor','r','MarkerSize',25);
%make FaceColor coded according to reply from click
%number each click
%write data to text file
end

How to manually segment and label ROIs in an image in Matlab?

I'm a newbie to Matlab. I'm basically attempting to manually segment a set of images and then manually label those segments also. I looked into the imfreehand(), but I'm unable to do this using imfreehand().
Basically, I want to follow the following steps :
Manually segment various ROIs on the image (imfreehand only lets me draw one segment I think?)
Assign labels to all those segments
Save the segments and corresponding labels to be used further (not sure what format they would be stored in, I think imfreehand would give me the position and I could store that along with the labels?)
Hopefully use these labelled segments in the images to form a training dataset for a neural network.
If there is some other tool or software which would help me do this, then any pointers would be very much appreciated. (Also I am new to stackoverflow, so if there is any way I could improve on the question to make it clearer, please let me know!) Thanks!
Derek Hoiem, a computer vision research at the University of Illinois, wrote an object labelling tool which does pretty much exactly what you asked for. You can download it from his page:
http://www.cs.illinois.edu/homes/dhoiem/software/index.html

How to print figure to clipboard by PRINT function with the quality identical to 'Edit-->Copy Figure' option?

Is there any way to print the figure to the clipboard so that the quality is identical to what the Edit-->Copy Figure option provides?
I used to save the figure to powerpoint file by using saveppt.m obtained from Matlab Central. It worked well until yesterday. I noticed that the stored image quality was somehow degraded. I tried to re-generate some ppt slides with exactly the same script and the same source data, but the new slides are simply of worse quality.
I investigated into this problem a little bit and discovered that when the figure is copied to clipboard by running print -dmeta, the image in the clipboard is already degraded, while if I use the Edit-->Copy Figure option in the figure window, I get the image as clear as the original image in the figure window.
Following is an example for your reference. I copied the image from a figure to the clipboard by two different methods, and paste it to Microsoft Paint program, and cut a piece of it to show below:
The image using print -dmeta:
The image using Edit-->Copy Figure:
If you compare the Xtick label '50', you may see that the image from Edit-->Copy Figure is smoother.
At the beginning I thought it was a problem of the resolution, but setting -rN to change the resolution does not seem to resolve my problem, at least not for N<=300.
Thank you for your help.
The short answer... Use the same function invoked in the callback for that menu item:
editmenufcn(gcf,'EditCopyFigure');
The longer answer... How exactly did I find this? You can look at my previous answer to a related question about reproducing what is done by a File menu option. The concept is the same, just for a different figure menu. For example, this will find the callback you want for the currently active figure window:
>> hCopyFigure = findall(gcf,'Label','Copy &Figure'); %# Handle for the "Copy
%# Figure" menu item
>> get(hCopyFigure,'Callback') %# Callback invoked when that item is selected
ans =
editmenufcn(gcbf,'EditCopyFigure')
The function EDITMENUFCN is another one of those sparsely documented functions, but looking through the code (by typing edit editmenufcn.m) shows that it either invokes Java (if you're on a Mac) or the undocumented function UIMENUFCN.
I think I found the answer myself. Using print -dmeta -painters to specify the renderer resolves my problem.
In File-->Preference-->Figure Copy Template-->Copy Option I noticed there are 3 options:
Metafile
Preserve information
Bitmap
I found that if I select 1, the Edit-->Copy Figure outputs the same image as print -dmeta. So I kind of confirmed the information I need is in the Preserve information option. A quick google search led me to the discussion about the potential difference of the applied renderer, and eventually I confirmed that using painters will print the image to the clipboard in the way I wanted.
The image in the question seems to be generated by the renderer zbuffer and painters, respectively. I still don't know why the default renderer of paint -dmeta changes, though.