MATLAB: Vector Manipulation – How to achieve this specific form doublemanipulationMATLABvectorvectors Hi all, I want to receive an expression like this: sos = {[1 8761]' [2 8762]' [3 8763]' [4 8764]' … [8760 17520]'}; Do you have an idea on how to achieve this? Best Answer Try this:v1 = 1:17520; % Create Vectorv2 = reshape(v1, [], 2)'; % Reshape Vector To 2-Row Matrixc = mat2cell(v2, 2, ones(1,size(v2,2))); % Create Cell Arrayq1 = v2(:,1:5); % View Original Matrix Sample (Delete Later)q2 = [c{1:5}] % View Cell Array Sample (Delete Later)q2 = 1 2 3 4 5 8761 8762 8763 8764 8765I created separate assignments for clarity. Note that ācā is a (1x8760) cell array, the format requested. Related SolutionsMATLAB: How to write Continue Long Statements on Multiple Lines Use repmat to avoid manually typing all 160 of those ā%qā repeats! Try this: formatSpec = ['%f',repmat('%q',1,160), '%[^\n\r]']; MATLAB: How to concatenate string vectors of unequal length Try this:% Define component cell arrays.v1 = {'a'; 'b'; 'c'}v2 = {'d'}v3 = {'e'; 'f'}% Find out how big cell array needs to be.lv1 = length(v1);lv2 = length(v2);lv3 = length(v3);rows = max([lv1,lv2,lv3])% Instatiate cell array of the max size.v4 = cell(rows, 3)% stuff each column in.v4(1:lv1, 1) = v1;v4(1:lv2, 2) = v2;v4(1:lv3, 3) = v3;% Print out resultsfprintf('\n\nHere is the output cell array:\n');v4In the command window:Here is the output cell array:v4 = 'a' 'd' 'e' 'b' [] 'f' 'c' [] [] Related QuestionReshape and Modify a cell arrayHow to store values in second column of cell arrayDear friends, the long matlab command that I have written is error. I want to be spelled the same way but without error.Matlab: element wise complex conjugate transpose
Best Answer