export matlab output to an excel file with location specified for a range of data - matlab

I want to export matlab output to an excel file starting from G2 column and for this the code i had written is exporting the data correctly but not to the desired location .It is printing in 21st number of rows rather than 2nd.
the code is
ResultFile = xlsread('filename');
sz= size(ResultFile,1);
b= num2str(sz+1);
location = strcat('G2',b);
fprintf('value in location is %g\n',location);
xlswrite('filename',fnlarray,'Sheet1',location);

In the command
xlswrite(filename,A,sheet,xlRange)
you can either specify xlRange as a string defining the corners of the desired output region, or (provided that you have specified the sheet) only give the coordinates of the upper-left cell. If you want to write an array to a region "below and to the right of G2", this should be enough:
location = 'G2';
Concatenating 'G2' with the number of rows of the excel file + 1 does not really seem to make sense to me right now.

Related

Using last date value from input file as label text in gnuplot

I have some input data from a file looking like this:
06.03.2020 62,30
09.03.2020 60,16
10.03.2020 59,94
11.03.2020 59,34
12.03.2020 56,58
13.03.2020 56,37
I am able to plot the data how I want to, but as the input data and the resulting graph will be updated automatically I would like to display the up-to-date status of the graph and input data by printing the last value of column 1 as a label in the graph.
So far I have tried something like
set term unknown
plot [:][:] input.txt using (xlast=$1):2
set terminal qt
set label xlast at graph 0.025, graph 0.95 left
plot ...
but I did not manage to get an output to the graph.
Can someone please help me out?
Thanks
Try to use strcol(1), I guess $1 tries to extract a number.
Code:
### last value of column to label
reset session
$Data <<EOD
06.03.2020 62,30
09.03.2020 60,16
10.03.2020 59,94
11.03.2020 59,34
12.03.2020 56,58
13.03.2020 56,37
EOD
set table $Dummy
plot $Data u (LastX=strcol(1)) w table
unset table
set label LastX at graph 0.025, graph 0.95 left
plot $Data u 0:(rand(0)) w l notitle
### end of code
Result:

If Measure Value = Something Then X Else Y End

I have 2 lines as measure values and I would like each line having their own % information but I cannot do that as a Text. Any workaround to get it to work?
Tableau file sample:
https://www.dropbox.com/s/1upehg61rg5psas/Percentage_on_success.twbx?dl=0
You should try a dual-axis with your two line measures and put the bars as reference lines. See this as an example. You can't independently control the Text on "Measure Values" because it is treated as a single measure.

Writing Real-Time data from Motion Capture System to a CSV file?

I am currently working on a project that incorporates the VICON Motion Capture System to analyze step length in subjects. The system uses infrared cameras with markers to create 3D models. The VICON system is currently set-up to use DataStreamSDK to allow for real-time data recording in MATLAB. My ultimate goal is to extract the data from one particular marker (XYZ coordinates) and export that data to a txt file so that I may edit it later). I have integrated pre-existing code as well as some of my original code to allow me to extract the coordinates for a particular marker and attempt to put those coordinates in a CSV file that adds a new coordinate with each frame. When I run the code, however, the CSV file seems to consist of only repeats of the coordinate from its most recent frame after I told the data to stop streaming. Instead, I would like the coordinates from each frame to be input onto a new line of the CSV file. I have provided the piece of the code below. If needed, I can provide the entire code, however most of it deals with enabling the streaming of the data from the VICON Nexus program. The portion that writes to the CSV file is at the bottom.
How should I edit the code so that it will update the CSV file continuously as new data is pulled, instead of simply putting 1:n repeats of the most recently pulled coordinate point? Thank you in advance.
for MarkerIndex = 9:9
% Get the marker name
MarkerName = MyClient.GetMarkerName( SubjectName, MarkerIndex ).MarkerName;
% Get the marker parent
MarkerParentName = MyClient.GetMarkerParentName( SubjectName, MarkerName ).SegmentName;
% Get the global marker translation
Output_GetMarkerGlobalTranslation = MyClient.GetMarkerGlobalTranslation( SubjectName, MarkerName );
fprintf( ' Marker #%d: %s (%g, %g, %g) %s\n', ...
MarkerIndex - 1, ...
MarkerName, ...
Output_GetMarkerGlobalTranslation.Translation( 1 ), ...
Output_GetMarkerGlobalTranslation.Translation( 2 ), ...
Output_GetMarkerGlobalTranslation.Translation( 3 ), ...
AdaptBool( Output_GetMarkerGlobalTranslation.Occluded ) );
ftemp = fopen('TestData.txt','w' );
for Output_GetFrameNumber = 1:n
fprintf(ftemp, '%f,%f,%f\n',Output_GetMarkerGlobalTranslation.Translation( 1 ),Output_GetMarkerGlobalTranslation.Translation( 2 ),Output_GetMarkerGlobalTranslation.Translation( 3 ));
end
fclose(ftemp);
end
You need to change the statement that opens the file for writing. You have:
ftemp = fopen('TestData.txt','w' );
The 'w' argument opens the file and discards the existing contents. So you are overwriting the file in every loop. If you use 'a', it will append contents to the file. See the docs here and read about the "permission" argument.
So you can just change 'w'' to 'a' and your code should work. In addition, you could consider opening the file outside the loop:
ftemp = fopen('TestData.txt','a');
for MarkerIndex = 9:9
% [insert your code for getting position data]
for Output_GetFrameNumber = 1:n
fprintf(ftemp, '%f,%f,%f\n',...); % [insert your print statement]
end
end
close(ftemp)
This will improve performance by minimizing the operations inside the loop.

loading multiple tiff images as matrices from a dir

my problem is this one:
I have a directory full of .tif images and I want to import them in MATLAB each one as a matrix.
If I do right click on the file in the dir and say "Import Data" it works: I have a matrix of elements that are my pixels that I can treat with imagesc and so on.
I want to make it automatic with a script.
what I have written is this one but it opens the Import Wizard, ask me to click enter for importing the first one and then stops.
contents = dir('*pulse1us100ms26_00*'); % this is part of the name of the images I want to load
for i = 1:numel(contents)
filename = contents(i).name;
uiimport(filename);
end
??? Error using ==> uiimport at 65
Cannot open the Import Wizard on a file while the Import Wizard is open.
May you please help me?
I think imread may be what you need,
% this is part of the name of the images I want to load
contents = dir('pulse1us100ms26_00*');
for i = 1:numel(contents)
filename = contents(i).name;
im = imread(filename,'tiff');
imagesc(im(:,:,1:3))
pause(3)
end
The result will be a matrix of uint8 from 0 to 255 (depending on the picture format). You can then work with them as needed.

Extracting data from grib file based on latitude and longitude

If i have a grib2 file that contains information for whole world (for some parameters) and I want to extract data from it using wgrib2 based on latitude and longitude given by user (client software to server). I tried following command but I am getting complete grib2 file only:
wgrib2.exe input.grb -undefine out-box 10:90 -10:10 -grib output.grb
Please tell me where am I going wrong? Thanks.
This is still the top hit on Google, so even though it is a bit old, here is a more detailed explanation.
First, you need wgrib2 from the National Weather Service Climate Prediction Centre. (The installation of that is straightforward, but not too well explained. See this page, or this gist for help.)
Next, you need to use the lola function (for LOngitude-LAtitude grid).
You need to give wgrib2 several arguments:
the grib file that has the data
the longitude information:
the longitude of the southwest corner of your bounding box
the length of the bounding box in degrees
the spacing of the points in this direction
the latitude information, the same as above
the latitude of the southwest corner of your bounding box
the length of the bounding box in degrees
the spacing of the points in this direction
the file name to write to
the format of the file to write (either bin for binary, text for simple text, spread for spreadsheet format, or grib for grib2).
For example:
wgrib2 input.grb 220:100:1 20:50:1 output.grb2 grib
will create an output file that covers north america (220 E - 320 E; 20 N - 70 N) at 1 degree intervals in both directions.
Rob
I used the following command to extract information from grib2 file.
wgrib2.exe input_file.grib2 -lola LonSW:#lon:dlon LatSW:#lat:dlat file format
assuming that we are having following co-ordinates for selection:
Top: (x0,y0) (x1,y0)
Bottom: (x0,y1) (x1,y1)
"LongSW"=x0, #lon = (x0~x1), "LatSW"=y0, #lat = (y0~y1).
and dlon and dlan can be kept as 1. 'file' is the output file name and format can be grib, csv, text etc.
Substitute above values in the command shown above and you should get the answer.
If your chosen longitude was 360 and latitude was 90:
wgrib2.exe input_file.grb2 -lon 360 90 > output_file.txt
I think you can also use cdo directly on grib for this
cdo sellonlatbox,lon1,lon2,lat1,lat2 in.grb out.grb
If the grib file is on a reduced gaussian grid you may need to specify that you want a regular lat-lon output. I usually convert the output format to netcdf myself using "-f nc" as I find it easier to process in other software.